BZOJ1271: [BeiJingWc2008]秦腾与教学评估

题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1271

题解:

这种题真是太神了!

只需要考虑被覆盖的次数的奇偶性,并且保证满足题意的点至多只有一个,所以考虑前缀和

该点以前前缀和都是偶数,该点及以后都是奇数! 然后就可以二分这个位置了。。。orz

给想出这道题的人跪了!

代码:

 1 #include<cstdio>
 2 
 3 #include<cstdlib>
 4 
 5 #include<cmath>
 6 
 7 #include<cstring>
 8 
 9 #include<algorithm>
10 
11 #include<iostream>
12 
13 #include<vector>
14 
15 #include<map>
16 
17 #include<set>
18 
19 #include<queue>
20 
21 #include<string>
22 
23 #define inf 2147483647
24 
25 #define maxn 250000
26 
27 #define maxm 500+100
28 
29 #define eps 1e-10
30 
31 #define ll long long
32 
33 #define pa pair<int,int>
34 
35 #define for0(i,n) for(int i=0;i<=(n);i++)
36 
37 #define for1(i,n) for(int i=1;i<=(n);i++)
38 
39 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
40 
41 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
42 
43 #define mod 1000000007
44 
45 using namespace std;
46 
47 inline int read()
48 
49 {
50 
51     int x=0,f=1;char ch=getchar();
52 
53     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
54 
55     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
56 
57     return x*f;
58 
59 }
60 int n,s[maxn],t[maxn],d[maxn];
61 int calc(int x)
62 {
63     int ret=0;
64     for1(i,n)if(s[i]<=x)ret+=(min(x,t[i])-s[i])/d[i]+1;
65     return ret;    
66 }
67 
68 int main()
69 
70 {
71 
72     freopen("input.txt","r",stdin);
73 
74     freopen("output.txt","w",stdout);
75 
76     int cs=read();
77     while(cs--)
78     {
79         n=read();
80         for1(i,n)s[i]=read(),t[i]=read(),d[i]=read();
81         ll l=0,r=inf,mid;
82         while(l<=r)
83         {
84             mid=(l+r)>>1;
85             if(calc(mid)&1)r=mid-1;else l=mid+1;
86                 //cout<<l<<' '<<r<<' '<<mid<<endl;
87             //cout<<( calc(mid)&1 )<<endl;
88         }
89         if(r==inf)printf("Poor QIN Teng:(\n");else printf("%lld %d\n",l,calc(l)-calc(l-1));
90     }
91 
92     return 0;
93 
94 }
View Code

 

posted @ 2014-11-10 11:13  ZYF-ZYF  Views(272)  Comments(0Edit  收藏  举报