HDU - 1172
思路:假设答案是x,那么x必定满足所有语句给定的条件。例如3585和4815就有2个相同的数,1和相同的位。
只要这个数满足所有条件,那么就是一个可能的答案,当答案数量超过1个时,就是"Not sure"
AC代码
#include <cstdio> #include <cmath> #include <algorithm> #include <cstring> #include <utility> #include <string> #include <iostream> #include <map> #include <set> #include <vector> #include <queue> #include <stack> using namespace std; #pragma comment(linker, "/STACK:1024000000,1024000000") #define eps 1e-10 #define inf 0x3f3f3f3f #define PI pair<int, int> typedef long long LL; const int maxn = 100 + 5; struct node{ int num[4]; int x, y; }a[maxn]; int w[4], vis[4]; bool is_ok(int ind) { memset(vis, 0, sizeof(vis)); int c1 = 0, c2 = 0; for(int i = 0; i < 4; ++i) { if(w[i] == a[ind].num[i]) ++c2; } for(int i = 0; i < 4; ++i) { for(int j = 0; j < 4; ++j) { if(vis[j]) continue; if(w[i] == a[ind].num[j] ) { vis[j] = 1; ++c1; break; } } } return c1 == a[ind].x && c2 == a[ind].y; } int cnt; int main() { int n; while(scanf("%d", &n) == 1 && n) { cnt = 0; int num, ans; for(int i = 0; i < n; ++i) { scanf("%d%d%d", &num, &a[i].x, &a[i].y); int cur = 3; while(num > 0) { a[i].num[cur--] = num % 10; num /= 10; } } for(int i = 1000; i < 10000; ++i) { int t = i; int cur = 3; while(t > 0) { w[cur--] = t % 10; t /= 10; } int flag = 1; for(int j = 0; j < n; ++j) { if(!is_ok(j)) { flag = 0; break; } } if(flag) { ans = i; ++cnt; } if(cnt >= 2) break; } if(cnt >= 2) printf("Not sure\n"); else printf("%d\n", ans); } return 0; }
如有不当之处欢迎指出!
HDU - 1172的更多相关文章
- hdu - 1172 猜数字 (思维题)
http://acm.hdu.edu.cn/showproblem.php?pid=1172 这个题换一种想法,可以找出四位数中所有满足条件的数看是否只有一个. #include <iostre ...
- hdu 1172 猜数字(暴力枚举)
题目 这是一道可以暴力枚举的水题. //以下两个都可以ac,其实差不多一样,呵呵 //1: //4 wei shu #include<stdio.h> struct tt { ],b[], ...
- HDU 1172 猜数字(DFS)
猜数字 Time Limit:10000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- HDU 1172 猜数字 (模拟)
题目链接 Problem Description 猜数字游戏是gameboy最喜欢的游戏之一.游戏的规则是这样的:计算机随机产生一个四位数,然后玩家猜这个四位数是什么.每猜一个数,计算机都会告诉玩家猜 ...
- hdu 1172 猜数字
猜数字 Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- 8-18-Exercise
8-18-小练 A.HDU 1172 猜数字 采用枚举~[赤果果的暴力~] 代码: #include <iostream> #include <cstdio> #inclu ...
- DFS的基础训练清单
HDU 1010 (AC) HDU 1015 (AC) HDU 1016 (AC) HDU 1172 (AC) HDU 1312 (AC) POJ 2362 (AC,1011 ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
- [转] HDU 题目分类
转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...
随机推荐
- Win2003 设置远程连接限制数
在开发过程中,很多同事需要连接到一台Win2003服务器,但是连接人数超过了10个,就连接不上了.想设置一下连接限制数,可以如下操作: 1:在运行里面输入gpedit.msc后,弹出"本地计 ...
- 用powershell实现:“倩女幽魂姥姥”版《语音报警系统》
------[第一章 前言]------ win7,及以上版本中,是自带语音库的,系统自带一套女声中文库,一套女声英文库.用powershell调用,从而发音,制作报警系统.是一件太简单的事情,只需要 ...
- Android Acitivy切换平移动画效果实现
1.在anim目录下新建anim文件夹,新建tran_in.xml和tran_out.xml分别表示下一页切换进入,和本页切换出去. 即in表示下一页向左平移,out表示同样向左平移至消失. tran ...
- 2018-01-28-M个本地工作点代码同步到N个GIT远端
layout: post title: 2018-01-28-M个本地工作点代码同步到N个GIT远端 key: 20180128 tags: IT GIT modify_date: 2018-01-2 ...
- MySQL--pt-osc工具学习
##=====================================================##pt-osc之工作流程:1.检查更改表是否有主键或唯一索引,是否有触发器2.检查修改表 ...
- 基于 HTML5 WebGL 的 3D SCADA 主站系统
这个例子的初衷是模拟服务器与客户端的通信,我把整个需求简化变成了今天的这个例子.3D 的模拟一般需要鹰眼来辅助的,这样找产品以及整个空间的概括会比较明确,在这个例子中我也加了,这篇文章就算是我对这次项 ...
- oralce plsql案例练习
以下plsql程序用的scott用户的dept,emp表. 案例1 --查询80,81,82,87年员工入职人数 set serveroutput on declare cursor cemp is ...
- Java中的代码点和代码单元(转)
文章来源:http://blog.csdn.net/weizhaozhe/article/details/3909079 这篇文章讲的很细,但是对于初学者也很难理解,在后面的笔记中,我会陈述自己的简单 ...
- CSS选择器的组合选择器之后代选择器和子元素选择器
实例代码: <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF ...
- Cookie、session和localStorage、以及sessionStorage之间的区别
一.Cookie.session和localStorage的区别 cookie的内容主要包括:名字.值.过期时间.路径和域.路径与域一起构成cookie的作用范围.若不设置时间,则表示这个cookie ...