HDU 5214 MOVIE(灵活题)

Today, they want to choose some wonderful scenes from a movie. A movie has  N scenes can be chosen, and each scene is associate with an interval [ LR].  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 parameters  N, L1, R1, a, b, c, d, and you can generate  L1 ~  LNR1 ~  RN by these parameters.
Input The first line contains a single integer  T, indicating the number of test cases.

Each test case contains seven integers  N, L1, R1, a, b, c, d, meaning that there are  Nscenes. 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's  Li 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 with  N > 100 is less than 5%.
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

http://acm.hdu.edu.cn/showproblem.php?pid=5214

题意:是否能找到三个区间,互不交叉。

直接找出首位两端 首段r值最小 末端l值最大

然后再直接枚举 看能不能找出符合要求的

#include<cstdio>
#include<cstdlib>
#include<cstring>
const int maxn = 10000010;
unsigned int l[maxn],r[maxn];
int main(){
    int test;
    scanf("%d",&test);
    while (test--){
        unsigned int n,a,b,c,d,tem;
        scanf("%d%d%d%d%d%d%d",&n,&l[1],&r[1],&a,&b,&c,&d);
        for (int i=2;i<=n;i++){
			l[i]=l[i-1]*a+b;
			r[i]=r[i-1]*c+d;
		}
        for (int i=1;i<=n;i++){
			if (l[i]>r[i])
				swap(l[i],r[i]);  //这一步不能少 
		}
        unsigned int x=r[1],y=l[1]; //边界4294967296 
        for (int i=2;i<=n;i++){
            if (r[i]<x) x = r[i];  //右边界最小值 
            if (l[i]>y) y = l[i];  //左边界最大值 
        }
        int flag = 0;
        for (int i=1;i<=n;i++){
			if (l[i]>x&&r[i]<y) 
		 		flag = 1;
		}
        if(flag) 
			printf("YES\n");
		else 
			printf("NO\n");
    } 
    return 0;
}

你可能感兴趣的:(HDU 5214 MOVIE(灵活题))