hdu 1172 猜数字 解题报告<暴力枚举>
2012-09-13 12:28
501 查看
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1172
View Code
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; }
相关文章推荐
- hdu 3929 Big Coefficients 解题报告 <容斥原理>
- HDU 1172 猜数字(暴力枚举)
- HDU 1172 猜数字 暴力枚举
- hdu 1172 猜数字(暴力枚举)
- poj 3370 Halloween treats 解题报告 <鸽巢原理>
- HDU 1172 猜数字(枚举)
- Leetcode<6 ZigZag Conversion>解题报告
- HDU 4920 Matrix multiplication 解题报告(暴力)
- POJ 1166&IOI 1994 The blocks 暴力枚举 解题报告
- HDU 1172 猜数字(枚举)
- HDU - 1172 猜数字 (暴力+模拟)
- HDU 1172 猜数字(暴力)
- HDU 4876 ZCC loves cards (2014多校联合训练第二场1005) 解题报告(暴力+剪枝)
- Hdu 3986 【枚举】【最短路】 解题报告
- hdu1172(暴力枚举)
- HDU解题报告——1172
- hdu 1172 猜数字(枚举)
- hdu 1172 猜数字(枚举)
- HDU 1172 猜数字(暴力)
- 解题报告: HDU_4407 Sum 容斥+暴力