hdu 5214

   吃了不少的TLE和WA    主要是开空间太烦    刚开始用数组开不了10000000的空间  用指针分配也出错   后来发现用结构体可以 


Problem Description

Cloud and Miceren like watching movies. 

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 [$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 parameters $N,~L_1,~R_1,~a,~b,~c,~d$, and you can generate $L_1$ ~ $L_N$, $R_1$ ~ $R_N$ 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,~L_1,~R_1,~a,~b,~c,~d$, meaning that there are $N$ scenes. The i-th scene's interval is [$L_i,~R_i$]. $L_1$ and $R_1$ have been stated in input, and $L_i~=~(L_{i - 1}~*~a~+~b)~mod~4294967296,~R_i~=~(R_{i - 1}~*~c~+~d)~mod~4294967296$. 

After all the intervals are generated, swap the i-th interval's $L_i$ and $R_i$ if $L_i~>~R_i$.


$T$ is about 100.

$1~\le~N~\le~10000000$.

$1~\le~L_1, R_1~\le~2000000000$.

$1~\le~a, b, c, d~\le~1000000000$.

The ratio of test cases with $N~\gt~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


  解题思路比较简单  

找到minr(结束时间最早的) 和 maxl(开始时间最晚的)   遍历一遍查找是否有场景的开始时间大于minr且该场景的结束时间小于maxl即可

#include "stdio.h"

#include "string.h"

#include "stdlib.h"


struct note{

    unsigned int l;

    unsigned int r;

}p[10000000];


int main()

{

   int t;

   scanf("%d",&t);

   while(t--)

    {

       int n,sum=0;

       unsigned int a,b,c,d,maxl=0,minr;

        minr=4294967296-1;

       scanf("%d%u%u%u%u%u%u",&n,&p[0].l,&p[0].r,&a,&b,&c,&d);

        a=a%4294967296;

        b=b%4294967296;

        c=c%4294967296;

        d=d%4294967296;

       for(int i=1;i<n;i++)

        {

           p[i].l=(p[i-1].l*a+b)%4294967296;

           p[i].r=(p[i-1].r*c+d)%4294967296;

        }

       for(int i=0;i<n;i++)

        {

           if(p[i].l>p[i].r)

            {

               unsigned int tmp=p[i].l;

               p[i].l=p[i].r;

               p[i].r=tmp;

            }

           if(p[i].l>maxl) maxl=p[i].l;

           if(p[i].r<minr) minr=p[i].r;

        }

       for(int i=0;i<n;i++)

        {

           if(p[i].l>minr&&p[i].r<maxl)

            {

                sum=1;

               break;

            }

        }

       if(sum==1)

           printf("YES\n");

       else

           printf("NO\n");

    }

    return 0;

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值