hdu 1172推測数字解題報告

10541 ワード

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


View Code
 1 #include <cstdio>

 2  #include <iostream>

 3  #include <cmath>

 4  #include <cstdlib>

 5  #include <cstring>

 6  #include <algorithm>

 7  using namespace std;

 8  typedef long long LL;

 9  int s[110][3];

10  int test( int n, int t )

11  {

12      int a[4], b[4], c[4]={0, 0, 0, 0}, k=0;

13      a[0]=n%10, a[1]=(n/10)%10, a[2]=(n/100)%10, a[3]=n/1000;

14      b[0]=s[t][0]%10, b[1]=(s[t][0]/10)%10, b[2]=(s[t][0]/100)%10, b[3]=s[t][0]/1000;

15      for( int i=0;i<4;++i ){

16          if( a[i]==b[i] )k++;

17      }

18      if( k!=s[t][2] )return 0;

19      k=0;

20      for( int i=0; i<4; ++ i ){

21          for(int j=0; j<4; ++ j  ){

22              if( a[i]==b[j]&& c[j]==0){

23                  c[j]=1;

24                  k++;

25                  break;

26              }

27          }

28      } 

29      if( k==s[t][1] )return 1;

30      return 0;

31      

32  }

33  int main( )

34  {

35      int N;

36      while(scanf ("%d", &N ), N){

37          for (int i=0; i<N; ++i ){

38              scanf( "%d%d%d", &s[i][0], &s[i][1], &s[i][2] );

39          }

40          int k=0, ans, flag, i, j;

41          for( i=1000; i<10000; ++ i ){

42              for(  j=0;j<N; ++ j ){

43                  flag=test( i, j );

44                  if( flag==0 )break;    

45              }

46              if( j==N ){

47                  k++;

48                  ans=i;

49                  if(k==2)break;

50              }

51          }

52          if( k==1 ) printf( "%d
", ans ); 53 else puts( "Not sure" ); 54 } 55 //system( "pause" ); 56 return 0; 57 } 58