?
?
题面:
?
Movie
Time Limit: 14000/7000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 967 Accepted Submission(s): 239
Problem Description Cloud and Miceren like watching movies.
Today, they want to choose some wonderful scenes from a movie. A movie has
Now, can you tell them if they can choose such three scenes that any pair of them do not overlap?
Since there are so many scenes that you can't get them in time, we will give you seven parameters
Input The first line contains a single integer
Each test case contains seven integers
After all the intervals are generated, swap the i-th interval's
The ratio of test cases with
Output For each test, print one line.
If they can choose such three scenes, output YES, otherwise output NO.
Sample Input
2 3 1 4 1 1 1 1 3 1 4 4 1 4 1
Sample Output
NO YES
Source 赛码BestCoder杯中国大学生程序设计冠军赛
题意:是否能找到三个区间,互不交叉。
?
?
解题:开始没想到贪心,后来仔细一想还是挺清晰的,取两头最边上的,中间遍历,这样都找不到可行解的话,自然就无解了。排序实际上是没有必要的,排个序都O(nlogn)了,遍历一遍只需O(n)。
?
坑点:
1.l,r可能开始就大小相反
2.全部生成完数据后,才交换。
?
代码:
?
#include#include using namespace std; struct info { unsigned int l,r; }store[10000005]; unsigned MAX(unsigned a,unsigned b) { if(a>b)return a; else return b; } unsigned MIN(unsigned a,unsigned b) { if(a >t; bool flag; while(t--) { cnt=0; flag=false; cin>>n>>le>>ri>>a>>b>>c>>d; if(le>ri) { minri=le; maxle=ri; } else { minri=ri; maxle=le; } store[cnt].l=le; store[cnt].r=ri; cnt++; for(unsigned i=1;i maxle) maxle=tmp; tmp=MAX(le,ri); if(tmp minri&&ri ?
?
?