hdu 5214 Movie(贪心)
来源:互联网 发布:exe软件修改器 编辑:程序博客网 时间:2024/04/29 10:44
Movie
Time Limit: 14000/7000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1390 Accepted Submission(s): 324
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
题目大意:给出一些区间,判断这些区间当中是否有至少三个不重叠的区间
题目分析:
很明显的贪心题,先找到最小的右边界,然后找到左边界比当前右边界大的区间中最小的右边界,如果能找够3次,那么说明是yes
比较坑的是,需要全部左右边界生成之后,再判断每一个边界是否要交换左右端点
题目分析:
很明显的贪心题,先找到最小的右边界,然后找到左边界比当前右边界大的区间中最小的右边界,如果能找够3次,那么说明是yes
比较坑的是,需要全部左右边界生成之后,再判断每一个边界是否要交换左右端点
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#define MAX 10000007using namespace std;struct Node{ unsigned l,r;}p[MAX];unsigned n,a,b,c,d;int t;int main ( ){ scanf ( "%d" , &t ); while ( t-- ) { scanf ( "%u" , &n ); scanf ( "%u%u" , &p[0].l , &p[0].r ); scanf ( "%u%u%u%u" , &a , &b , &c , &d ); for ( int i = 1 ; i < n ; i++ ) { p[i].l = p[i-1].l*a + b; p[i].r = p[i-1].r*c + d; //if ( p[i].l > p[i].r ) swap ( p[i].l , p[i].r ); } for ( int i = 0 ; i < n ; i++ ) if ( p[i].l > p[i].r ) swap ( p[i].l , p[i].r ); int flag = 0; unsigned cur = 0xffffffff, pos = -1; while ( flag < 3 ) { cur = 0xffffffff; for ( int i = 0 ; i < n ; i++ ) if ( p[i].l > pos || !flag ) cur = min ( cur , p[i].r ); // cout << "CUr : " << cur << " " << pos << endl; if ( cur == 0xffffffff ) break; else pos = cur , flag++; // cout << "YES : " << flag << endl; } if ( flag == 3 ) puts ( "YES" ); else puts ("NO"); }}
0 0
- HDU 5214 - Movie (贪心)
- hdu 5214 Movie(贪心)
- hdu 5214 Movie
- HDU 5214 MOVIE
- HDU 5214 Movie
- HDU 5214 Movie
- HDU ACM 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
- GUI菜单练习
- pycharm开发python时出现控制台显示中文乱码
- cocos2d-js ttf字体总结(史上最详细教程)。
- 动态配置脚本实现之 链接库方法提取
- VS2013 以管理员方式启动
- hdu 5214 Movie(贪心)
- PHP多维数组排序
- 程序员面试宝典 zigzag数组问题 p92 new二维数组
- iOS: UIWindow in iOS
- Mosquito的优化——epoll优化(七)
- 2015-6-8-python正则表达式模块的使用
- checkbox取值问题
- Android Studio: Android Manifest doesn't exists or has incorrect root tag
- 获取某个城市的所有lab与获得有lab的所有城市