码迷,mamicode.com
首页 > 其他好文 > 详细

[HDU5214]Movie解题报告|小水题大智慧

时间:2015-05-05 23:41:29      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:

Movie

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 [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.
 
  给定一些区间,然后求是否存在三个互不覆盖的区间...
  直接贪心,找出一个右边界最左的,和一个左边界最右的
  再找是否存在一个区间能与这两个区间互不交叉
  
  然而当我乐呵呵地开了int64之后发现MLE了...
  技术分享
  然后想了半天...除了多次reset之外根本找不到不存l,r的方法啊...
  那就存吧..发现官方题解上说用unsigned int,自然溢出真好啊!本来还担心10位乘10位int64也会乘爆
  然后发现Pas里面还真有一个这样神奇的东西叫做longword...
  乐呵呵地交了一发发现WA掉了...
  机智地放弃了Pas..我相信一定是longword的自然溢出出现了问题
  然后用C++写..就陷入了漫长的RE...
  最后发现是变量开在了int main()里面...
  唔...
 
 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cstring>
 4 const int maxn = 10000010;
 5 unsigned int l[maxn],r[maxn];
 6 int main(){
 7     int test;
 8     scanf("%d",&test);
 9     while (test--){
10         unsigned int n,a,b,c,d,tem;
11         scanf("%d%d%d%d%d%d%d",&n,&l[1],&r[1],&a,&b,&c,&d);
12         for (int i=2;i<=n;i++) l[i]=l[i-1]*a+b,r[i]=r[i-1]*c+d;
13         for (int i=1;i<=n;i++) if (l[i]>r[i]){tem=l[i];l[i]=r[i];r[i]=tem;}
14         unsigned int x=r[1],y=l[1];
15         for (int i=2;i<=n;i++){
16             if (r[i]<x) x = r[i];
17             if (l[i]>y) y = l[i];
18         }
19         int flag = 0;
20         for (int i=1;i<=n;i++) if (l[i]>x&&r[i]<y) flag = 1;
21         if (flag) printf("YES\n");else printf("NO\n");
22     }
23     return 0;
24 }

 

 
  晚安
 
  05/.May

[HDU5214]Movie解题报告|小水题大智慧

标签:

原文地址:http://www.cnblogs.com/mjy0724/p/4480288.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!