Hdu1172 violent water

Source: Internet
Author: User
Guess number

Time Limit: 20000/10000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 2722 accepted submission (s): 1585


Problem description guess digital games are one of Gameboy's favorite games. The rules of the game are as follows: The computer randomly generates a four-digit number, and then the player guesses what the four-digit number is. Each time you guess a number, the computer will tell the player to guess a few numbers, and several of them are in the correct position.
For example, the random number generated by a computer is 1122. If a player guesses 1234, because the numbers 1 and 2 exist in both numbers, and the positions of 1 in the two numbers are the same, the computer will tell the player to guess the two numbers, one of them is in the correct position. If a player guesses 1111, the computer will tell him to guess two numbers, two in the correct position.
Now, let's give you a conversation between Gameboy and the computer. Your task is to determine what the four digits are based on this conversation.

 

There are multiple groups of input data. The first behavior in each group is a positive integer N (1 <=n <= 100), indicating that there are n questions and answers in this dialog. In the next n rows, each row has three integers A, B, and C. Gameboy guessed that the four-digit number is A, and then the computer answered the correct B number, where C is in the correct position. When n = 0, the input data ends.

 

Output: each group of input data corresponds to a row of output. If the four-digit number can be determined based on this dialog, the four-digit number is output. If not, the "not sure" is output ".

 

Sample input64815 2 15716 1 07842 1 04901 0 08585 3 38555 3 224815 0 02999 3 30

 

Sample output3585not sure enumeration 1000-9999 one-to-one comparison, the number of qualified conditions is num, num> 1 output not sure; num = 1 output number; num = 0 output nothing. The idea is easy to write with the code. Code:
 1 #include <cstdio> 2 #include <algorithm> 3 #include <cstring> 4 #include <iostream> 5 #include <queue> 6 #include <vector> 7  8 using namespace std; 9 10 queue<int>Q;11 12 int pd(int num1,int x,int y,int num){13     int n1, n2;14     n1=n2=0;15     int a[4], b[4], c1[10], c2[10];16     memset(c1,0,sizeof(c1));17     memset(c2,0,sizeof(c2));18     int i, f1, f2;19     f1=f2=1;20     for(i=0;i<4;i++){21         a[i]=num1%10;22         c1[a[i]]++;23         num1/=10;24     }25     for(i=0;i<4;i++){26         b[i]=num%10;27         c2[b[i]]++;28         num/=10;29     }30     for(i=0;i<4;i++){31         if(a[i]==b[i]) n1++;32     }33     for(i=0;i<10;i++){34         n2+=min(c1[i],c2[i]);35     }36     if(n2==x&&n1==y) return 1;37     else return 0;38 }39 40 main()41 {42     int n, i, j, k;43     int x, y, z, num, size;44     while(scanf("%d",&n)==1&&n){45         scanf("%d %d %d",&x,&y,&z);46         while(!Q.empty()) Q.pop();47         for(i=1000;i<=9999;i++){48             if(pd(x,y,z,i)) Q.push(i);49         }50         n--;51         while(n--){52             scanf("%d %d %d",&x,&y,&z);53             size=Q.size();54             if(size==0) continue;55             while(size--){56                 num=Q.front();57             //    printf("%d ",num);58                 Q.pop();59                 if(pd(x,y,z,num)) Q.push(num);60             }61         //    cout<<endl<<endl;62         }63         if(Q.size()==1) printf("%d\n",Q.front());64         else if(Q.size()==0) continue;65         else printf("Not sure\n");66     }67 }

 

Hdu1172 violent water

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.