Problem Description
猜数字游戏是gameboy最喜欢的游戏之一。游戏的规则是这样的:计算机随机产生一个四位数,然后玩家猜这个四位数是什么。每猜一个数,计算机都会告诉玩家猜对几个数字,其中有几个数字在正确的位置上。
比如计算机随机产生的数字为1122。如果玩家猜1234,因为1,2这两个数字同时存在于这两个数中,而且1在这两个数中的位置是相同的,所以计算机会告诉玩家猜对了2个数字,其中一个在正确的位置。如果玩家猜1111,那么计算机会告诉他猜对2个数字,有2个在正确的位置。
现在给你一段gameboy与计算机的对话过程,你的任务是根据这段对话确定这个四位数是什么。
 

 

Input
输入数据有多组。每组的第一行为一个正整数N(1<=N<=100),表示在这段对话***有N次问答。在接下来的N行中,每行三个整数A,B,C。gameboy猜这个四位数为A,然后计算机回答猜对了B个数字,其中C个在正确的位置上。当N=0时,输入数据结束。
 

 

Output
每组输入数据对应一行输出。如果根据这段对话能确定这个四位数,则输出这个四位数,若不能,则输出"Not sure"。
 

 

Sample Input
6 4815 2 1 5716 1 0 7842 1 0 4901 0 0 8585 3 3 8555 3 2 2 4815 0 0 2999 3 3 0
 

 

Sample Output
3585 Not sure
 
思路:
本来我想DFS去做,但是发现边界条件太难找了。 实在想不出来有啥好方法。后来一看题解? 卧槽???  枚举???? 
这题从1000->9999 的所有数你都去枚举, 找到满足题意的那个就可以了。
 
  1 #include <iostream>
  2 #include <algorithm>
  3 #include <stdlib.h>
  4 #include <string>
  5 #include <string.h>
  6 #include <set>
  7 #include <queue>
  8 #include <math.h>
  9 #include <stdbool.h>
 10 
 11 #define LL long long
 12 #define inf 0x3f3f3f3f
 13 using namespace std;
 14 const int MAXN=1000005;
 15 
 16 typedef struct Node{
 17     int a;
 18     int b;
 19     int c;
 20 }Node;
 21 
 22 Node node[100];
 23 int n;
 24 
 25 bool judge(int i,int num)
 26 {
 27     int num1[5],num2[5];
 28     bool vis[5];
 29     for(int j=1;j<=4;j++)
 30         vis[j]=false;
 31     num1[1] = node[i].a/1000;
 32     num1[2] = (node[i].a%1000)/100;
 33     num1[3] = (node[i].a%100)/10;
 34     num1[4] = (node[i].a%10);
 35 
 36     num2[1] = num/1000;
 37     num2[2] = (num%1000)/100;
 38     num2[3] = (num%100)/10;
 39     num2[4] = (num%10);
 40 
 41     int cnt = 0;
 42     for (int j=1;j<=4;j++)
 43     {
 44         if (num1[j] == num2[j])
 45             cnt++;
 46     }
 47     if (cnt != node[i].c)
 48         return false;
 49 
 50     cnt = 0;
 51     for (int j=1;j<=4;j++)
 52     {
 53         for (int k=1;k<=4;k++)
 54         {
 55             if (num1[j] == num2[k] && !vis[k])
 56             {
 57                 vis[k] = true;
 58                 cnt++;
 59                 break;
 60             }
 61         }
 62     }
 63     if (cnt != node[i].b)
 64         return false;
 65     return true;
 66 }
 67 
 68 
 69 
 70 int main()
 71 {
 72     //freopen("../in.txt","r",stdin);
 73     while (~scanf("%d",&n))
 74     {
 75         if (n == 0)
 76             break;
 77         for (int i=1;i<=n;i++)
 78         {
 79             scanf("%d%d%d",&node[i].a,&node[i].b,&node[i].c);
 80         }
 81         int count = 0;
 82         bool flag = true;
 83         int result = 0;
 84         for (int num=1000;num<=9999;num++)
 85         {
 86             for (int i=1;i<=n;i++)
 87             {
 88                 flag = judge(i,num);
 89                 if (!flag)
 90                     break;
 91             }
 92             if (flag)
 93             {
 94                 count++;
 95                 result = num;
 96             }
 97         }
 98         if (count == 1)
 99             printf("%d\n",result);
100         else
101             printf("Not sure\n");
102     }
103     return 0;
104 }