Hdu-1172-猜数字 [枚举]
来源:互联网 发布:淘宝网购物女装短裙 编辑:程序博客网 时间:2024/06/02 06:15
题目传送门
因为题目限定为4位数,所以读入所有情况,并从1000枚举到9999,判断是否有1个数满足所有条件,如果有即输出,如果有超过1个或者没有,就输出Not sure。
#include <algorithm>#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;struct node{ int A,B,C;} p[100];int check(int x, int y){ int num1 = 0, num2 = 0; int book1[10], book2[10]; memset(book2,0,sizeof(book2)); memset(book1,0,sizeof(book1)); for (int i = 1; i <= 1000; i*=10) { int xx = x/i%10; int yy = p[y].A/i%10; if (xx==yy) num1++; book1[xx]++; book2[yy]++; } for (int i = 0; i < 10; i++) { num2+=min(book1[i],book2[i]); } if (num1==p[y].C && num2==p[y].B) return 1; return 0;}int main(void){ int n; while (scanf("%d", &n),n) { int book[10000]; memset(book,0,sizeof(book)); for (int i = 0; i < n; i++) scanf("%d %d %d", &p[i].A, &p[i].B, &p[i].C); int sum=0; int num=-1; for (int i = 1000; i<=9999; i++) { int f = 0; if (!book[i]) { for (int j = 0; j < n; j++) { if (!check(i,j)) { f=1; book[i]=1; break; } } if (f==0) { num = i; sum++; } } } if (sum!=1) printf("Not sure\n"); else printf("%d\n",num); } return 0;}
0 0
- hdu 1172 猜数字(枚举)
- Hdu-1172-猜数字 [枚举]
- HDU 1172 猜数字(枚举)
- HDU 1172 猜数字(暴力枚举)
- HDU 1172 猜数字 暴力枚举
- hdu 1172 猜数字 (枚举)
- HDU 1172猜数字(直接暴力枚举即可)
- hdu 1172 猜数字
- hdu 1172 猜数字
- hdu 1172 猜数字
- hdu(1172)猜数字
- hdu 1172 猜数字
- HDU-1172 猜数字
- hdu 1172 猜数字
- HDU 1172 猜数字
- hdu-1172 猜数字
- hdu 1172 猜数字
- Hdu 1172 猜数字
- Android O(SDK 8.0)新特性
- 蓝底彩照变白底,MATLAB能帮您实现
- 525. Contiguous Array
- activiti学习笔记5--history configuration--20170405
- convolution by numpy
- Hdu-1172-猜数字 [枚举]
- 线程同步与互斥——信号量
- Python开发必备神器之一:virtualenv
- 递归递推练习―G―小银考呀考不过四级
- Java8---5.方法引用
- 如何获取大量随机数
- 设计模式(二十) 观察者模式
- Python: 熟悉又陌生的字符编码(转载)
- 学习笔记--C++ autotools工具使用