標籤:des style http color java os io strong
Flyer
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1537 Accepted Submission(s): 552
Problem DescriptionThe new semester begins! Different kinds of student societies are all trying to advertise themselves, by giving flyers to the students for introducing the society. However, due to the fund shortage, the flyers of a society can only be distributed to a part of the students. There are too many, too many students in our university, labeled from 1 to 2^32. And there are totally N student societies, where the i-th society will deliver flyers to the students with label A_i, A_i+C_i,A_i+2*C_i,…A_i+k*C_i (A_i+k*C_i<=B_i, A_i+(k+1)*C_i>B_i). We call a student "unlucky" if he/she gets odd pieces of flyers. Unfortunately, not everyone is lucky. Yet, no worries; there is at most one student who is unlucky. Could you help us find out who the unfortunate dude (if any) is? So that we can comfort him by treating him to a big meal!
InputThere are multiple test cases. For each test case, the first line contains a number N (0 < N <= 20000) indicating the number of societies. Then for each of the following N lines, there are three non-negative integers A_i, B_i, C_i (smaller than 2^31, A_i <= B_i) as stated above. Your program should proceed to the end of the file.
OutputFor each test case, if there is no unlucky student, print "DC Qiang is unhappy." (excluding the quotation mark), in a single line. Otherwise print two integers, i.e., the label of the unlucky student and the number of flyers he/she gets, in a single line.
Sample Input
21 10 12 10 145 20 76 14 35 9 17 21 12
Sample Output
1 18 1
Source2013 ACM/ICPC Asia Regional Changchun Online
二分尋找,且要用64位整型,先統計標籤數目,為偶數則必然不存在任何一個人為奇數的情況。
然後,在用二分尋找。
#include"stdio.h"#include"string.h"#include"iostream"using namespace std;#define N 20005#define inf 0x7fffffff#define LL __int64#define max(a,b) ((a)>(b)?(a):(b))#define min(a,b) ((a)<(b)?(a):(b))LL a[N],b[N],d[N];int main(){ int i,n; while(~scanf("%d",&n)) { LL sum,l,r,t; sum=r=0; l=inf; for(i=0;i<n;i++) { scanf("%I64d%I64d%I64d",&a[i],&b[i],&d[i]); t=(b[i]-a[i])/d[i]; sum+=t+1; r=max(r,a[i]+t*d[i]); l=min(l,a[i]); } if(sum%2==0) printf("DC Qiang is unhappy.\n"); else { LL mid,num,y; while(l<=r) { mid=(l+r)/2; num=0; sum=0; for(i=0;i<n;i++) { if(a[i]>mid) continue; if(mid<=b[i]) t=(mid-a[i])/d[i]; else if(mid>b[i]) t=(b[i]-a[i])/d[i]; sum+=t+1; if(a[i]+t*d[i]==mid||mid==a[i]) //統計邊界點mid的數目 num++; y=mid; } if(num%2) break; //該點就是奇數點 if(sum%2) r=mid-1; else l=mid+1; } printf("%I64d %I64d\n",y,num); } } return 0;}