思路:假设答案是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. 使用SoapUI调用Vsphere Web Service

    项目中经常需要调用Webservice进行验证测试,下面就介绍下如何使用测试工具SoapUI调用Vsphere vcenter的 Web Service VSphere的Webservice地址默认为 ...

  2. spring的jar各包作用

    http://yjwen337.blog.163.com/blog/static/3625847820106132949858/[转]spring.jar是包含有完整发布的单个jar 包,spring ...

  3. TP手册学习第一天

    调试执行的sql语句 User::get(1); echo User::getLastSql(); 方法直接返回当前的查询SQL而不执行fetchSql echo User::fetchSql()-& ...

  4. js内置函数大全及基本使用方法(一)

    一,常规函数 alert函数:显示一个警告对话框,包括一个OK按钮. 语法:alert("hello world"); confirm函数:显示一个确认对话框,包括OK.Cance ...

  5. sed的N;P用法

    sed的N;P用法 原文地址 这里介绍的是sed的一个多行模式的使用,一开始对sed中命令N的用法不是很理解,经过多次尝试,通过几个例子对N的用法进行总结: N即Next,它同n(next)的区别是: ...

  6. CentOS 7修改网卡名称

    CentOS 7 修改网卡名为eth0 标签: linux 笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 CentOS7的网卡名称太长,这不符合我们的使用习惯, ...

  7. 用户 'IIS APPPOOL\.NET v4.5 Classic' 登录失败。

    我在win8.1系统下用vs2013+SqlServer08编写完项目后,挪到另一台win8.1系统(安装了Vs2010+SqlServer08)中,把网址挂到IIs中时,出现如下错误 : 解决方案: ...

  8. Oracle中的游标

    Oracle游标 概念:内存中的一块区域,存放select结果 游标用来处理从数据库中检索的多行记录(使用SELECT语句).利用游标,程序可以逐个地处理和遍历一次检索返回的整个记录集.一.显示游标( ...

  9. 多线程访问DataTable

    项目中需要读取数据库中的多张表.由于表的数据比较多,串行读取时耗时比较多,所以对程序做了一点优化. 环境 .NET 3.5,SQL Server 2012,Visual Studio 2015 过程 ...

  10. 弥补wxpython无背景图片缺陷

    思路: 通过设置Panel的背景样式为wx.BG_STYLE_CUSTOM: self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) 绑定Panel的背景事情: sel ...