猜数字 -- 暴力法
来源:互联网 发布:fifa18球员数据查询 编辑:程序博客网 时间:2024/05/16 04:48
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1172
/*猜数字http://acm.hdu.edu.cn/showproblem.php?pid=1172*/#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm>#include <set>using namespace std;#define N 105int n;struct data{ int a,b,c; };data v[N]; // gameboy猜这个四位数为A,然后计算机回答猜对了B个数字,其中C个在正确的位置上bool isOk(int num , int k){ int a[4],b[4]; a[0] = num / 1000; a[1] = num / 100 - a[0] * 10; a[2] = num /10 - a[0] * 100 - a[1] * 10; a[3] = num % 10; b[0] = v[k].a / 1000; b[1] = v[k].a / 100 - b[0] * 10; b[2] = v[k].a /10 - b[0] * 100 - b[1] * 10; b[3] = v[k].a % 10; int i , j; int cr = 0 ; for(i = 0 ; i < 4 ; i ++) { if(a[i] == b[i]) cr ++ ; } if(cr == v[k].c) { int br = 0 ; bool mark[4] = {false}; // 避免重复 for(i = 0; i < 4 ; i ++) // a[i] { for(j = 0 ; j < 4 ; j ++) // b[j] { if(a[i] == b[j] && mark[j] == false) { br ++ ; mark[j] = true; break; } } } if(br == v[k].b ) return true; } return false;}int main(){ //freopen("in.txt","r",stdin); while(scanf("%d",&n) != EOF && n != 0) { int num , b , c; for(int i = 0 ; i < n ; i ++) { scanf("%d%d%d",&v[i].a , &v[i].b , &v[i].c); } int ans = -1; int count = 0; bool flag = false; for(int num=1000; num<=9999; num++) { for(int i = 0 ; i < n ; i++) { flag = isOk(num,i); if(flag == false) break; } if(flag){ count ++; ans = num ; } } // 只有一个结果时确定 if(count != 1) printf("Not sure\n"); else printf("%d\n",ans); } return 0; }
0 0
- 猜数字 -- 暴力法
- HDU1172 猜数字 【暴力】
- 猜数字-暴力枚举
- HDOJ1172 猜数字 【暴力枚举】
- HDU 1172 猜数字(暴力)
- HDU 1172 猜数字(暴力枚举)
- HDOJ 题目1172猜数字(暴力)
- 杭电1172 猜数字(暴力)
- HDU 1172 猜数字(暴力)
- hdoj 1172 猜数字(暴力)
- HDU 1172 猜数字 暴力枚举
- 暴力:数字排列
- HDU 1172猜数字(直接暴力枚举即可)
- HDU 1172 猜数字 (傻逼暴力题)
- hdoj 猜数字 1172 (暴力模拟&&技巧)
- 2017蓝桥杯官方模拟赛 猜数字(暴力枚举)
- 蓝桥杯 特殊的数字(暴力)
- Bailian4146 Bailian2747 数字方格【暴力】
- 使用qsort进行字符串数组排序
- DIR 命令 详解
- CCF-出现次数最多的数-201312-1
- 【dfs+回溯】hdu 2553 N皇后问题
- keySet和entrySet的区别
- 猜数字 -- 暴力法
- [宏]_IOC_NR, _IOC_TYPE, _IOC_SIZE, _IOC_DIR
- iOS跳转到设置页面
- 就近调用原则
- Two Pointers - Stack - Trapping Rain Water
- 剑指offer整理归纳(1/2)
- HTML5 文件操作
- 从官网下载apache
- CCF-ISBN号码-201312-2