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

Educational Codeforces Round 27 C

时间:2017-08-23 19:05:13      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:bool   else   sort   bsp   pre   code   scanf   return   space   

题意:给出一些节目的播放区间,问有2个电视的你是否可以看完全部节目,不可重合

思路:模拟

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 struct node{
 5     int l,r;
 6 }a[200005];
 7 bool cmp(node p,node q){
 8     return p.l<q.l;
 9 }
10 int main(){
11     int n;
12     cin>>n;
13     for(int i=1;i<=n;i++){
14         scanf("%d%d",&a[i].l,&a[i].r);
15     }
16     sort(a+1,a+1+n,cmp);
17     int l1=a[1].r,l2;
18     int y;
19     for(int i=2;i<=n;i++){
20         if(a[i].l<=l1){
21             l2=a[i].r;y=i;break;
22         }
23         else l1=a[i].r;
24     }
25 
26     for(int i=y+1;i<=n;i++){
27         if(a[i].l>l1){
28             l1=a[i].r;
29         }
30         else if(a[i].l>l2){
31             l2=a[i].r;
32         }
33         else {
34             cout<<"NO"<<endl;return 0;
35         }
36     }
37     cout<<"YES"<<endl;
38     return 0;
39 }

 

Educational Codeforces Round 27 C

标签:bool   else   sort   bsp   pre   code   scanf   return   space   

原文地址:http://www.cnblogs.com/hhxj/p/7419553.html

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