思路:假设答案是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. 在CMainFrame里使用定时器是有讲究的

    设置定时器函数:SetTimer 单位毫秒 销毁定时器函数:KillTimer 消息:WM_TIMER 注意事项: (1)不要在构造函数里设置定时器. (2)不要在析构函数里销毁定时器. 原因:构造函 ...

  2. Log4j源码解析--核心类解析

    原文出处:http://www.blogjava.net/DLevin/archive/2012/06/28/381667.html.感谢上善若水的无私分享. 在简单的介绍了Log4J各个模块类的作用 ...

  3. strstr()与find()

  4. nodejs爬虫笔记(一)---request与cheerio等模块的应用

    目标:爬取慕课网里面一个教程的视频信息,并将其存入mysql数据库.以http://www.imooc.com/learn/857为例. 一.工具 1.安装nodejs:(操作系统环境:WiN 7 6 ...

  5. [squid] kid1| ERROR: No forward-proxy ports configured.

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  6. [DeeplearningAI笔记]改善深层神经网络_优化算法2.6_2.9Momentum/RMSprop/Adam优化算法

    Optimization Algorithms优化算法 觉得有用的话,欢迎一起讨论相互学习~Follow Me 2.6 动量梯度下降法(Momentum) 另一种成本函数优化算法,优化速度一般快于标准 ...

  7. libGDX-wiki发布

    为方便大家学习和访问,我将libgdx的wiki爬取到doku-wiki下,专门建立了以下地址.欢迎大家来共同完善. http://wiki.v5ent.com

  8. Power shell 重启IIS

    最近根据项目需要写了一段power shell的代码 ,主要功能是批量重启IIS 具体的 Power shell 服务如下: write-output 'Restarting IIS servers ...

  9. 高通HAL层之Sensor HAL

    高通的HAL层其实分为两种,一种是直接从kernel这边报数据上来的,由sensor HAL层来监听,另一种是走ADSP的模式,HAL层是通过qmi的形式进行监听的: 走ADSP架构的可以看下面的博客 ...

  10. Unable to add window -- token android.os.BinderProxy@3a067204 is not valid错误分析记录

    打开APP时,出现闪退的情况,查看android studio报错信息,主要为: Unable to add window -- token android.os.BinderProxy@3a0672 ...