思路:假设答案是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的更多相关文章

  1. hdu - 1172 猜数字 (思维题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1172 这个题换一种想法,可以找出四位数中所有满足条件的数看是否只有一个. #include <iostre ...

  2. hdu 1172 猜数字(暴力枚举)

    题目 这是一道可以暴力枚举的水题. //以下两个都可以ac,其实差不多一样,呵呵 //1: //4 wei shu #include<stdio.h> struct tt { ],b[], ...

  3. HDU 1172 猜数字(DFS)

    猜数字 Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  4. HDU 1172 猜数字 (模拟)

    题目链接 Problem Description 猜数字游戏是gameboy最喜欢的游戏之一.游戏的规则是这样的:计算机随机产生一个四位数,然后玩家猜这个四位数是什么.每猜一个数,计算机都会告诉玩家猜 ...

  5. hdu 1172 猜数字

    猜数字 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  6. 8-18-Exercise

    8-18-小练 A.HDU 1172   猜数字 采用枚举~[赤果果的暴力~] 代码: #include <iostream> #include <cstdio> #inclu ...

  7. DFS的基础训练清单

    HDU 1010  (AC) HDU 1015    (AC) HDU 1016     (AC) HDU 1172   (AC) HDU 1312   (AC) POJ 2362  (AC,1011 ...

  8. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  9. [转] HDU 题目分类

    转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...

随机推荐

  1. Linkin大话PC常用快捷键

    不管是不是程序员,常用的键盘的快捷键还是要会的,以下整理一些最常用的也比较重要的PC快捷键. 复制:CTRL+C 剪切:CTRL+X 粘贴:CTRL+V 全选:CTRL+A 撤销键:CTRL+Z 切换 ...

  2. linkin大话面向对象--封装和隐藏

    软件开发追求的境界:高内聚,低耦合 高内聚:尽可能把模块的内部数据,功能实现细节隐藏在模块内部独立完成,不允许外部直接干预 低耦合:仅暴露少量的方法给外部使用 到底为什么要对一个雷或者对象实现良好的封 ...

  3. Linux make nginx 的时候报错

    报错如下: `conf/koi-win' and `/usr/local/nginx/conf/koi-win' are the same file   原因: 可能在编译 nginx 的时候步骤不对 ...

  4. test for python socket

    server: #!/usr/bin/python import socket import threading import time def tcplink(sock, addr): print ...

  5. <%@include file="a.jsp"%> jsp引用jsp文件时候注意

    被包含的a.jsp文件:    a.jsp文件的page指令要么不要写.要么与主jsp文件的page指令一样.

  6. 02_HTML5+CSS3详解第五、六天(实战篇之HTML5制作企业网站)

    [废话连篇 - 实战篇,没什么好说的,最后一章兼容性问题懒得看了,over] Details 一.Xmind部分 xmind教程:http://www.jianshu.com/p/7c488d5e4b ...

  7. Python CRM项目三

    1.分页: 分页使用Django内置的分页模块来实现 官方的分页案例 from django.core.paginator import Paginator, EmptyPage, PageNotAn ...

  8. Redis进阶实践之十 Redis主从复制的集群模式

    一.引言        Redis的基本数据类型,高级特性,与Lua脚本的整合等相关知识点都学完了,说是学完了,只是完成了当前的学习计划,在以后的时间还需继续深入研究和学习.从今天开始来讲一下有关Re ...

  9. easyui_datagrid 行内使用comobox的编码实现

    easyui datagrid组件的列属性中有一个editor属性,官方介绍如下: 所以,我们可以通过编码实现datagrid行内插入comobox的方式来实现某些场合的需要,具体编码实现如下: // ...

  10. python+xlsxwriter+PIL自动压图贴图到Excel小工具

    一.环境 windows10/mac + python3.6 python第三方库 xlsxwriter.PIL.argparse 二.需求 1.运行每条测试case成功与否都需要把截图放在img文件 ...