HDU 4768 flyer (Binary Search)

Source: Internet
Author: User

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 distribution age, the flyers of a society can only be distributed to a part of the students. there are too tables, too tables 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. cocould 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 abve. your program shocould 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

Perform a binary search and use a 64-bit integer. count the number of tags first. If the number is an even number, no human is required.

Then, use binary search.

# 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]) // count the number of mid at the boundary point num ++; y = mid;} If (Num % 2) break; // This point is an odd point if (sum % 2) R = mid-1; else l = Mid + 1;} printf ("% i64d % i64d \ n", Y, num) ;}} return 0 ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.