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

POJ-2376 Cleaning Shifts

时间:2019-08-22 12:39:03      阅读:80      评论:0      收藏:0      [点我收藏+]

标签:main   ast   ==   div   printf   sdi   typedef   bool   dig   

 1 #include <iostream>
 2 #include <algorithm>
 3 #define _for(i,a,b) for(int i = (a);i < b;i ++)
 4 #define _rep(i,a,b) for(int i = (a);i > b;i --)
 5 #define INF 0x3f3f3f3f
 6 typedef long long ll;
 7 using namespace std;
 8 inline ll read()
 9 {
10     ll ans = 0;
11     char ch = getchar(), last =  ;
12     while(!isdigit(ch)) last = ch, ch = getchar();
13     while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - 0, ch = getchar();
14     if(last == -) ans = -ans;
15     return ans;
16 }
17 inline void write(ll x)
18 {
19     if(x < 0) x = -x, putchar(-);
20     if(x >= 10) write(x / 10);
21     putchar(x % 10 + 0);
22 }
23 struct section
24 {
25     int l;
26     int r;
27     bool operator < (section b)
28     {
29         if(l != b.l)
30             return l < b.l;
31         return r < b.r;
32     }
33 };
34 int N,T;
35 section a[25003];
36 int main()
37 {
38     N = read(),T = read();
39 
40     _for(i,1,N+1)
41         a[i].l = read(),a[i].r = read();
42     
43     sort(a+1,a+N+1);
44     
45     int l = 0,i = 0;
46     int rnt = 0;
47     while(l < T)
48     {
49         int maxr = -1;
50         while(a[++i].l <= l+1 && i < N+1)
51             maxr = max(maxr,a[i].r);
52         if(i > N+1)
53             break;
54         if(maxr==-1)    {printf("-1\n");return 0;}
55         rnt ++;
56         i --;
57         l = maxr;
58     }
59     printf("%d\n",rnt);
60     return 0;
61 }

 

POJ-2376 Cleaning Shifts

标签:main   ast   ==   div   printf   sdi   typedef   bool   dig   

原文地址:https://www.cnblogs.com/Asurudo/p/11393507.html

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