思路:假设答案是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. JQuery判断是否为空

    //有如下三种判断 var A=$("#**).val(); if(A==null||A!=undefined||A==""){ //处理 } //参考文章1说下面方法效 ...

  2. Bilibili/DanmakuFlameMaster: Android开源弹幕引擎·烈焰弹幕使 ~ JNI source:Bilibili/NativeBitmapFactory

    https://github.com/Bilibili/DanmakuFlameMaster

  3. Android Studio打包APK时出现 is not translated in "en" (English) [MissingTranslation]

    错误信息: Error:(16) Error: "baidutieba_client_inavailable" is not translated in "en" ...

  4. Android4.0新控件

    谷歌在推出Android4.0的同时推出了一些新控件,Android4.0中最常用的新控件有下面5种.  1. Switch的使用 Switch顾名思义,就是开关的意思,有开和关两种状态. 当Swit ...

  5. Ubuntu中使用dnw工具:没有找到/dev/secbulk0

    Ubuntu中使用dnw动机: 一. 之前没有用ubuntu中的dnw,想试试. 二. 因为换了win10系统,怕搞不定win10中dnw的驱动,想着在ubuntu中不用禁用数字签名啥的比较省心.(事 ...

  6. python并发编程之多进程(理论)

    一.什么是进程 进程:正在进行的一个过程或者说一个任务.而负责执行任务则是cpu. 二.进程与程序的区别 程序:仅仅是一堆代 进程:是指打开程序运行的过程 三.并发与并行 并发与并行是指cpu运行多个 ...

  7. C#基础(二)--之数据类型

    在第一章我们了解了C#的输入.输出语句后,我这一节主要是介绍C#的基础知识,本节的内容也是后续章节的基础,好的开端等于成功的一半.在你阅读完本章后,你就有足够的C#知识编写简单的程序了.但还不能使用继 ...

  8. encodeURI()和encodeURIComponent()

    encodeURI() 返回值 URIstring 的副本,其中的某些字符将被十六进制的转义序列进行替换. 说明 该方法会替换所有的字符,但不包括以下字符,即使它们具有适当的UTF-8转义序列: 保留 ...

  9. Matplotlib快速入门笔记

    我正以Python作为突破口,入门机器学习相关知识.出于机器学习实践过程中的需要,快速了解了一下matplotlib绘图库.下图是我学习过程中整理的一些概念. 本文将以该图为线索梳理相关概念. 简介 ...

  10. Spring-shiro源码陶冶-DefaultFilter

    阅读源码有助于陶冶情操,本文旨在简单的分析shiro在Spring中的使用 简单介绍 Shiro是一个强大易用的Java安全框架,提供了认证.授权.加密和会话管理等功能 Apache Shiro自带的 ...