标签:des style blog color os io java strong for
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2722 Accepted Submission(s): 1585
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 }
标签:des style blog color os io java strong for
原文地址:http://www.cnblogs.com/qq1012662902/p/3963601.html