HDU4768: Flyer (Binary)

Source: Internet
Author: User

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
N communities distribute leaflets with parameters a, B, and c. The rule is to distribute leaflets to numbers a, a + c .... a + k * c. The serial number must be smaller than or equal to B. One of the students receives only an odd number of leaflets and asks them to find the student's serial number and the number of leaflets.
Idea: it is still relatively simple to use an exclusive or operation, but it takes a long time to do so. The correct method is to use binary to divide intervals, because the sequence obtained by each community is an arithmetic difference series, we can easily obtain the number of leaflets distributed in the interval. If the number of leaflets is odd, the number of people who want them must be in the left range. Otherwise, the number of leaflets distributed in the right range is, in this way, find the answer.
Binary Code:
# Include
 
  
# Include
  
   
# Include using namespace std; # define ll _ int64 # define L 20005ll a [L], B [L], c [L], l, r, n; ll solve (ll mid) {ll k, sum = 0; int I; for (I = 0; I
   
    
= A [I]) sum + = (k-a [I])/c [I] + 1;} return sum;} int main () {int I, j; while (~ Scanf ("% d", & n) {for (I = 0; I
    
     
Exclusive or operation
#include 
      
       #include 
       
        #include using namespace std;#define ll __int64#define L 20005ll a[L],b[L],c[L];int main(){    int i,j,n;    while(~scanf("%d",&n))    {        for(i = 0; i
        
         

Related Article

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.