您的位置:首页 > 其它

hdu 1172 猜数字 解题报告<暴力枚举>

2012-09-13 12:28 501 查看
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1172

View Code

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
int s[110][3];
int test( int n, int t )
{
int a[4], b[4], c[4]={0, 0, 0, 0}, k=0;
a[0]=n%10, a[1]=(n/10)%10, a[2]=(n/100)%10, a[3]=n/1000;
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;
for( int i=0;i<4;++i ){
if( a[i]==b[i] )k++;
}
if( k!=s[t][2] )return 0;
k=0;
for( int i=0; i<4; ++ i ){
for(int j=0; j<4; ++ j  ){
if( a[i]==b[j]&& c[j]==0){
c[j]=1;
k++;
break;
}
}
}
if( k==s[t][1] )return 1;
return 0;

}
int main( )
{
int N;
while(scanf ("%d", &N ), N){
for (int i=0; i<N; ++i ){
scanf( "%d%d%d", &s[i][0], &s[i][1], &s[i][2] );
}
int k=0, ans, flag, i, j;
for( i=1000; i<10000; ++ i ){
for(  j=0;j<N; ++ j ){
flag=test( i, j );
if( flag==0 )break;
}
if( j==N ){
k++;
ans=i;
if(k==2)break;
}
}
if( k==1 ) printf( "%d\n", ans );
else puts( "Not sure" );
}
//system( "pause" );
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: