hdu

http://acm.hdu.edu.cn/showproblem.php?pid=1172

这个题换一种想法,可以找出四位数中所有满足条件的数看是否只有一个.

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 #include <vector>
 5 #include <cstring>
 6 #include <string>
 7 #include <algorithm>
 8 #include <string>
 9 #include <set>
10 #include <functional>
11 #include <numeric>
12 #include <sstream>
13 #include <stack>
14 #include <map>
15 #include <queue>
16 #pragma comment(linker, "/STACK:102400000,102400000")
17 #define CL(arr, val)    memset(arr, val, sizeof(arr))
18 
19 #define ll long long
20 #define inf 0x7f7f7f7f
21 #define lc l,m,rt<<1
22 #define rc m + 1,r,rt<<1|1
23 #define pi acos(-1.0)
24 
25 #define L(x)    (x) << 1
26 #define R(x)    (x) << 1 | 1
27 #define MID(l, r)   (l + r) >> 1
28 #define Min(x, y)   (x) < (y) ? (x) : (y)
29 #define Max(x, y)   (x) < (y) ? (y) : (x)
30 #define E(x)        (1 << (x))
31 #define iabs(x)     (x) < 0 ? -(x) : (x)
32 #define OUT(x)  printf("%I64d
", x)
33 #define lowbit(x)   (x)&(-x)
34 #define Read()  freopen("a.txt", "r", stdin)
35 #define Write() freopen("b.txt", "w", stdout);
36 #define maxn 1000000000
37 #define N 2510
38 #define mod 1000000000
39 using namespace std;
40 
41 struct point
42 {
43     int x,y,z;
44 }p[105];
45 
46 bool judge(int n,int m)
47 {
48     int a[5],b[5],used[5];
49     a[0]=n/1000,a[1]=n/100%10,a[2]=n/10%10,a[3]=n%10;
50     b[0]=p[m].x/1000,b[1]=p[m].x/100%10,b[2]=p[m].x/10%10,b[3]=p[m].x%10;
51    // for(int i=0;i<4;i++)
52        // printf("%d ",b[i]);
53         //printf("
");
54     int ans=0;
55     for(int i=0;i<4;i++)
56     {
57         if(a[i]==b[i]) ans++;
58     }
59    // printf("%d
",ans);
60     if(ans!=p[m].z) return false;
61     ans=0;
62     memset(used,0,sizeof(used));
63     for(int i=0;i<4;i++)
64         for(int j=0;j<4;j++)
65         if(!used[j]&&a[i]==b[j])
66         {
67              ans++;
68              used[j]=1;
69              //printf("%d %d
",a[i],b[j]);
70              break;
71         }
72    // printf("%d
",ans);
73     if(ans!=p[m].y) return false;
74     return true;
75 }
76 int main()
77 {
78    //freopen("a.txt","r",stdin);
79     int n;
80     while(~scanf("%d",&n)&&n)
81     {
82         for(int i=0;i<n;i++) scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].z);
83         int ans=0,cnt=0;
84         for(int i=1000;i<=9999;i++)
85         {
86             bool flag=0;
87             for(int j=0;j<n;j++)
88                 if(!judge(i,j)) {flag=1;break;}
89             if(!flag) {ans++;cnt=i;}
90         }
91       //  printf("%d
",ans);
92         if(ans==1) printf("%d
",cnt);
93         else printf("Not sure
");
94     }
95     return 0;
96 }
原文地址:https://www.cnblogs.com/nowandforever/p/4546568.html