hdu1172 guessing numbers (brute force enumeration)

Source: Internet
Author: User

Guess numbers

Time limit:20000/10000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 3373 Accepted Submission (s): 1975


Problem description Guess the number game is one of Gameboy's favorite games. The rules of the game are this: the computer randomly generates a four-digit number, and then the player guesses what the four-digit number is. Each guessing a number, the computer will tell the player to guess a few numbers, several of which are in the correct position.
For example, the computer randomly generates a number of 1122. If the player guesses 1234, because the two numbers exist in these two numbers at the same time, and 1 are in the same position in the two digits, the computer tells the player to guess 2 numbers, one in the correct position. If the player guesses 1111, then the computer will tell him to guess 2 numbers, 2 in the right position.
Now give you a Gameboy and computer dialogue process, and your task is to determine what this four-digit number is based on this conversation.

Input data has multiple groups. The first behavior of each group is a positive integer n (1<=n<=100), which indicates that there are n questions and answers in this conversation. In the next n rows, three integers per line are a,b,c. Gameboy Guess this four-digit number is a, and then the computer answers and guesses the B number, where C is in the correct position. When n=0, the input data ends.

Output each set of input data corresponds to a row of outputs. If this four-digit number is determined according to this conversation, the output of this four-digit number, if not, outputs "not sure".

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

Sample output3585not sure knowledge Point: Brute force enumeration difficulty: Judging the computer answer guessed the B number used to tag array.
1#include <cstdlib>2#include <cstdio>3#include <iostream>4#include <algorithm>5#include <cstring>6 using namespacestd;7 intd[5],e[5],vis[5];8 intt,cnt1,cnt2,cnt3,temp;9 structNumTen { One     inta,b,c; A }; -Num num[ -]; - BOOLJudgeintn,num k) the { -memset (Vis,0,sizeof(Vis)); -d[0]=n/ +; -d[1]=n/ -%Ten; +d[2]=n% -/Ten; -d[3]=n%Ten; +e[0]=k.a/ +; Ae[1]=k.a/ -%Ten; ate[2]=k.a% -/Ten; -e[3]=k.a%Ten; -      for(intI=0;i<4; i++) -         if(e[i]==D[i]) -cnt1++; -     if(cnt1==k.c) in     { -          for(intI=0;i<4; i++) to         { +              for(intj=0;j<4; j + +) -             if(d[i]==e[j]&&!Vis[j]) the             { *vis[j]=1; $cnt2++;Panax Notoginseng                  Break; -             } the         } +     } A     Else the     return false; +     if(cnt2==k.b) -         return true; $     Else $         return false; - } - intMain () the { -      while(~SCANF ("%d",&t))Wuyi     { the         if(t==0) -              Break; Wu          for(intI=0; i<t;i++) -scanf"%d%d%d",&num[i].a,&num[i].b,&num[i].c); Aboutcnt3=0; $         //int flag=0; -         BOOLflag=true; -          for(intI= +; i<=9999; i++) -             { A              for(intj=0; j<t;j++) +             { theCnt1=cnt2=0; -flag=judge (I,num[j]); $                 if(!flag) Break; the             } the             if(flag) the             { thecnt3++; -temp=i; in             } the             } the         if(cnt3!=1) About         { theprintf"Not sure\n"); the         } the         Else +printf"%d\n", temp); -  the     }Bayi  the     return 0; the } - /*6 - 4815 2 1 the 5716 1 0 the 7842 1 0 the 4901 0 0 the 8585 3 3 - 8555 3 2 the 2 the 4815 0 0 the 2999 3 394 0*/

hdu1172 guessing numbers (brute force enumeration)

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.