HDU 5214 MOVIE
来源:互联网 发布:复式组合软件 编辑:程序博客网 时间:2024/05/16 10:50
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5214
题面:
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 hasN scenes can be chosen, and each scene is associate with an interval [L , R ]. L is the beginning time of the scene and R is the ending time. However, they can't choose two scenes which have overlapping intervals. (For example, scene with [1, 2] and scene with [2, 3], scene with [2, 5] and scene with[3, 4]).
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 parametersN, L1, R1, a, b, c, d , and you can generate L1 ~ LN , R1 ~ RN by these parameters.
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 T , indicating the number of test cases.
Each test case contains seven integersN, L1, R1, a, b, c, d , meaning that there are N scenes. The i-th scene's interval is [Li, Ri ]. L1 and R1 have been stated in input, and Li = (Li−1 ∗ a + b) mod 4294967296, Ri = (Ri−1 ∗ c + d) mod 4294967296 .
After all the intervals are generated, swap the i-th interval'sLi and Ri if Li > Ri .
T is about 100.
1 ≤ N ≤ 10000000 .
1 ≤ L1,R1 ≤ 2000000000 .
1 ≤ a,b,c,d ≤ 1000000000 .
The ratio of test cases withN > 100 is less than 5%.
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".
If they can choose such three scenes, output "YES", otherwise output "NO".
Sample Input
23 1 4 1 1 1 13 1 4 4 1 4 1
Sample Output
NOYES
Source
赛码"BestCoder"杯中国大学生程序设计冠军赛
解题:开始没想到贪心,后来仔细一想还是挺清晰的,取两头最边上的,中间遍历,这样都找不到可行解的话,自然就无解了。排序实际上是没有必要的,排个序都O(nlogn)了,遍历一遍只需O(n)。
坑点:
1.l,r可能开始就大小相反
2.全部生成完数据后,才交换。
代码:
#include <iostream>#include <algorithm>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<b)return a; else return b;}int main(){ unsigned t,n,le,ri,a,b,c,d,tmp,cnt,minri,maxle; cin>>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<n;i++) { le=(le*a + b); ri=(ri*c + d); tmp=MIN(le,ri); if(tmp>maxle) maxle=tmp; tmp=MAX(le,ri); if(tmp<minri) minri=tmp; store[cnt].l=le; store[cnt].r=ri; cnt++; } for(int i=0;i<cnt;i++) { le=MIN(store[i].l,store[i].r); ri=MAX(store[i].l,store[i].r); if(le>minri&&ri<maxle) { flag=true; break; } } if(flag)cout<<"YES\n"; else cout<<"NO\n"; } return 0;}
0 0
- hdu 5214 Movie
- HDU 5214 - Movie (贪心)
- HDU 5214 MOVIE
- HDU 5214 Movie
- HDU 5214 Movie
- hdu 5214 Movie(贪心)
- 赛码1001 Movie(hdu 5214)
- HDU 5214 MOVIE(灵活题)
- HDU 3496 - Watch The Movie
- HDU 3496 Watch The Movie
- Hdu 3496 Watch The Movie
- hdu 3496 Watch The Movie
- hdu 3496 Watch The Movie
- hdu 3496 Watch The Movie
- HDU 3496 Watch The Movie
- hdu 3496 Watch The Movie
- HDU--3496 Watch The Movie
- HDU 3496 Watch The Movie
- 使用Xamarin + C#开发应用 -- 使用sqlite做本地存储
- 作为计算机专业学生,最应该学习的课程前五位是什么?【知乎】
- C++标准转换运算符static_cast
- 关于解析json数组中的json数组
- Mac下PHP环境搭建
- HDU 5214 MOVIE
- python写的二分查找
- Caused by: java.net.SocketException: Software caused connection abort: socket write error
- 位运算+枚举
- PHP单文件上传原理及上传函数的封装
- java Fork/Join框架实例详解
- 我用Cocos2d-x模拟《Love Live!学院偶像祭》的Live场景(一)
- 3Sum Closest
- 两种高性能I/O设计模式(Reactor/Proactor)的比较