CodeForces - 63C Bulls and Cows(暴力求解)

Bulls and Cows C++ Bulls and Cows,在linux下编译成功,完整程序 立即下载
Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u

Description

The "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess it.

The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number may have a leading zero. It can't have more than one leading zero, because all it's digits should be different. The guesser tries to guess the number. He makes a series of guesses, trying experimental numbers and receives answers from the first person in the format "x bulls y cows". x represents the number of digits in the experimental number that occupy the same positions as in the sought number. y represents the number of digits of the experimental number that present in the sought number, but occupy different positions. Naturally, the experimental numbers, as well as the sought number, are represented by four-digit numbers where all digits are different and a leading zero can be present.

For example, let's suppose that the thinker thought of the number 0123. Then the guessers' experimental number 1263 will receive a reply "1 bull 2 cows" (3 occupies the same positions in both numbers and 1 and 2 are present in both numbers but they occupy different positions). Also, the answer to number 8103 will be "2 bulls 1 cow" (analogically, 1 and 3 occupy the same positions and 0 occupies a different one).

When the guesser is answered "4 bulls 0 cows", the game is over.

Now the guesser has already made several guesses and wants to know whether his next guess can possibly be the last one.

Input

The first input line contains an integer n (1 ≤ n ≤ 10) which represents the number of already made guesses. Then follow n lines in the form of "aibici", where ai is the i-th experimental number, bi is the number of bulls, ci is the number of cows (1 ≤ i ≤ n, 0 ≤ bi, ci, bi + ci ≤ 4). The experimental numbers are correct, i.e., each of them contains exactly four digits, in each of them all the four digits are different, and there can be a leading zero. All the experimental numbers are different. As the guesser hasn't guessed the number yet, the answer "4 bulls 0 cows" is not present.

Output

If the input data is enough to determine the sought number, print the number with four digits on a single line. If it has less than four digits, add leading zero. If the data is not enough, print "Need more data" without the quotes. If the thinker happens to have made a mistake in his replies, print "Incorrect data" without the quotes.

Sample Input

Input
2
1263 1 2
8103 2 1
Output
Need more data
Input
2
1234 2 2
1256 0 2
Output
2134
Input
2
0123 1 1
4567 1 2
Output
Incorrect data


题目大意:
Bulls and Cows是一个猜数字游戏,一个人写下一个数字,另一个人猜这个数字,其中b代表数字正确,但是位置不正确的数字有几个,而c代表数字正确而且位置也正确的数字有几个。
其中猜的数字由 0 ~ 9 的不重复的4个数字组成。
给你n组数据,每行有三个数字,第一个是你猜的数字,第二个是b,第三个是c
现在如果可能猜出的结果有1个输出该数字,如果不止一个输出Need more data
如果结果不肯能出现输出Incorrect data


解析:
直接暴力求解,所有的结果,如果遇到求解的数字为符合所有的可能,记cnt++
如果cnt == 1 输出结果,cnt == 0 输出Incorrect data,如果cnt > 1输出Need more data

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 20;
struct Node {
	int num[4];
	int a,b;
}node[N];

int ans[4];
int vis[11];
bool ok(int num) {
	memset(vis,0,sizeof(vis));
	int t;
	for(int i = 0; i < 4; i++) {
		t = num % 10;
		if(vis[t]) {
			return false;
		}
		ans[i] = t;
		vis[t] = 1;
		num /= 10;
	}
	return true;
}
int main() {
	int n;
	char arr[5];
	while(scanf("%d",&n) != EOF) {
		for(int i = 0; i < n; i++) {
			scanf("%s %d %d",arr,&node[i].a,&node[i].b);
			for(int j = 0; j < 4; j++) {
				node[i].num[j] = arr[j] - '0';
			}
		}
		int cnt1,cnt2,cnt;
		cnt = 0;
		int res;
		for(int i = 1; i < 10000; i++) {
			if(ok(i)) {
				int j;
				for(j = 0; j < n; j++) {
					cnt1 = cnt2 = 0;
					for(int k = 0; k < 4; k++) {
						if(ans[k] == node[j].num[k]) {
							cnt1++;
						}
						if(vis[node[j].num[k]]) {
							cnt2++;
						}
					}
					if(cnt1 != node[j].a || cnt2 - cnt1 != node[j].b) {
						break;
					}
				}
				if(j == n) {
					res = i;
					cnt++;
				}
			}
		}
		if(cnt == 1) {
			for(int i = 0; i < 4; i++) {
				printf("%d",res%10);
				res /= 10;
			}
			printf("\n");
		}else if(cnt > 1){
			printf("Need more data\n");
		}else {
			printf("Incorrect data\n");
		}
	}
	return 0;
}

Visual Studio 命令提示符工具区别与使用场景 Visual Studio会提供一系列命令提示符工具,这些工具应用在哪些场景呢?本文进行了相关介绍。 阅读详情

相关推荐

igh ethercat 实时性测试

组备注std(us)max(us)a无锁核,无rt补丁8.38108b锁核+FIFO调度+内存锁定,无rt补丁0.9216c锁核+FIFO调度+内存锁定,+rt补丁0.9922可以看到 a组 使用ethercat不做其他优化,周期抖动非常大,且max能达到 100 多 us;通过 锁核+FIFO调度+内存锁定 进行优化,可以看到 抖动明显降低,且max 为 20 us 左右;

qq_43353632的博客 2309

CF63C Bulls and Cows 超详细题解

链接: 原题链接 题目描述 The “Bulls and Cows” game needs two people to play. The thinker thinks of a number and the guesser tries to guess it. The thinker thinks of a four-digit number in the decimal system. All the digits in the number are different and the number m

Syc1102g的博客 802

Win11/Win10系统下,Proe5.0 M280终极版保姆级安装与激活指南(含SSQ补丁避坑)

本文提供Win11/Win10系统下Pro/E 5.0 M280终极版的详细安装与激活指南,涵盖环境配置、SSQ补丁应用及常见问题解决方案。通过系统调整、分步安装和性能优化,确保软件在现代操作系统上的稳定运行,特别适合机械设计用户参考。

weixin_30895059的博客 442

bulls与cows的c语言程序设计,CodeForces - 63C Bulls and Cows(暴力求解)

Time Limit:2000MSMemory Limit:262144KB64bit IO Format:%I64d & %I64uDescriptionThe "Bulls and Cows" game needs two people to play. The thinker thinks of a number and the guesser tries to guess i...

weixin_39601794的博客 377

VConsole动态加载

// 移动端真机调试工具 vconsole import VConsole from "vconsole"; import Vue from "vue"; // 动态使用VConsole if(process.env.NODE_ENV==='production'){ if(process.env.VUE_APP_BASEURL.includes('test')||process.env.VUE_APP_BASEURL.includes('pre')){ Vue.prototype

aliven1的博客 1041

从时序博弈到数据稳定:CS1237驱动中的信号滤波与卡尔曼实践

本文探讨了CS1237高精度ADC驱动在复杂工业环境中的信号处理挑战,重点介绍了一阶滤波与自适应卡尔曼滤波算法的实践应用。通过参数优化和动态调整策略,有效提升了数据稳定性和抗干扰能力,为嵌入式系统在噪声环境下的精密测量提供了可靠解决方案。

rnn9storyteller的博客 863

CF-63C - Bulls and Cows(枚举)

C -Bulls and Cows Time Limit:2000MSMemory Limit:262144KB64bit IO Format:%I64d & %I64u SubmitStatusPracticeCodeForces 63C Description The "Bulls and Cows"...

weixin_30329623的博客 158

Fluent新手避坑:遇到‘Floating point exception’别慌,这7个排查步骤帮你搞定

本文为Fluent新手提供了遇到‘Floating point exception’错误时的7个详细排查步骤。从理解浮点异常的本质到边界条件检查、时间步长设置、求解器选择、网格优化、亚松弛因子调节以及高阶格式的取舍,帮助用户快速定位并解决问题,确保CFD仿真的稳定性和准确性。

weixin_30480075的博客 260

Codeforces CFGym 101192D. Bulls and cows

题意:交互式题目,猜数字的游戏。一方想一个四位数(每一位数字都不同),另一方每次猜一个四位数,该方回复一个两位数,第一位代表有多少个数字完全正确,第二位代表有多少个数字位置不正确但是包含在正确的四位数里,求不少于8次的猜法 分析:暴力。先存好所有的四位不同的数,然后随便选一个猜,得到回复后,在存好的数里所有满足这个回复的四位数中随机选择一个作为下一次要猜的数,再次得到回复之后,再在存好的数里面找...

zhlbjtu2016的博客 555

【模型解读】【代码复现】Segment Anything Model(SAM)

Meta AI的一个新的人工智能模型,只需一次点击就能 "分割出 "任何图像中的任何物体! SAM是一个可提示的分割系统,对不熟悉的物体和图像具有zero-shot的概括性,并且不需要额外的训练。

lalula的博客 2万+

基于STM32设计的老人摔倒检测报警系统(OneNet+MQTT)(235)

基于STM32设计的老人摔倒检测报警系统,不仅能够实时监测老人的位置信息,方便在紧急情况下快速定位,还能通过陀螺仪模块精确检测老人的身体姿态,一旦判断为摔倒状态,系统将立即触发蜂鸣器报警,并通过4G网络向指定联系人发送短信警示,确保老人能够迅速得到援助。此外,系统还支持老人主动按下设备上的按键发送求助短信,增强了系统的灵活性和实用性。

4691

B - Bulls and Cows CodeForces - 63C(构造,模拟)

B - Bulls and Cows CodeForces - 63C The “Bulls and Cows” game needs two people to play. The thinker thinks of a number and the guesser tries to guess it. The thinker thinks of a four-digit number in t...

tomjobs的博客 440

把冷门数据从内存里请出去:ABAP 环境下玩转 SAP HANA Native Storage Extension (NSE) 的开发者实战笔记

摘要:SAP HANA NSE技术为ABAP系统提供了一种经济高效的温数据管理方案。文章首先指出企业数据存在"温度分层"现象,高频访问的热数据需常驻内存,而低频温数据更适合存储在磁盘或闪存。NSE通过混合列存架构,将不常访问的数据移至磁盘但仍保持数据库内统一管理,显著降低内存成本。 关键实施要点包括:在ADT技术设置中将Load Unit设为"Page Enforced"以启用NSE;理解buffer cache作为数据"抽屉"的工作原理;掌握选表

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 162

CSUST 8.3 早训

A - Settlers' Training CodeForces - 63B 题意 给你一串数字,相同的数字为一组,每次可以给一组中的一个数字加一,问这一串数字全变成K需要多少步? 题解 模拟 C++代码 /** /*@author Victor /*language C++ */ //#include <bits/stdc++.h> #i...

weixin_30293135的博客 109

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Bulls and Cows问题及解法

299. Bulls and Cows LeetCode

刘天的博客 4107

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Bulls and Cows(C++猜数字游戏)

Bulls and Cows(C++猜数字游戏)

coolsunxu的博客 759

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

[299] Bulls and Cows

统计两个字符串中位置相同且值相同的元素个数和位置不同但值相同的元素个数。

camlot的博客 1064

猜数字游戏Bulls and Cows的解法

猜数字(又称 Bulls and Cows )是一种古老的的密码破译类益智类小游戏,起源于20世纪中期,一般由两个人或多人玩,也可以由一个人和电脑玩。查了网上很多关于这个游戏的帖子,大多都是计算机出题,人来猜。根据百度百科的介绍,有非常多种方法可以实现七步之内猜出答案。下面我就介绍其中最简单的一种也是我唯一会的一种方法。.........

weixin_44946764的博客 4660

软考中级 系统集成项目管理工程师:案例分析 25 分计算题 3 类核心公式速解

本文针对软考中级系统集成项目管理工程师考试中的案例分析计算题,详细解析了挣值管理、关键路径法和投资回收期三大核心计算题型。通过公式速解、步骤拆解和真题演练,帮助考生快速掌握25分计算题的解题技巧,提升考试通过率。

436

Bulls and Cows

You are playing the followingBulls and Cowsgame with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint tha...

leetcode 解题思路 465

LeetCode Bulls and Cows 数组

思路:关键是理解题意: A的意思是位置正确且数字正确的个数; B的意思是位置不正确但数字正确的个数。public class Solution { public String getHint(String secret, String guess) { char[] sc = secret.toCharArray(); char[] gc = guess.

在路上的学习者 1610

LeetCode299——Bulls and Cows我的解法

You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint tha

代码菌的blog 3544

UVA - 11059 Maximum Product (简单枚举)

Problem D - Maximum Product Time Limit: 1 second Given a sequence of integers S = {S1, S2, ..., Sn}, you should determine what is the value of the maximum positive product involving consecutive term

小G的ACM之路 1527

UVA - 11218 KTV(暴力求解)

Problem K KTV One song is extremely popular recently, so you and your friends decided to sing it in KTV. The song has 3 characters, so exactly 3 people should sing together each time (yes, there

小G的ACM之路 1240

hdu 5374 Tetris(模拟俄罗斯方块)

题意: 俄罗斯方块想必大家都玩过,现在题目给出了3种俄罗斯方块。 O形,I形,L形 以及5种操作,w选择,a左移一位,d右移以为,w下移一位,p什么都不做。然后又给出了方块出现的序列,要求按所给出的操作能消除多少行。 解析: DRAW数组表示已(x,y)(x,y)为左下角,能在图上画出的形状。 然后模拟每个每个方块,直到当前方块不能动位置,在二维数组中标记方块,然后接下来选

小G的ACM之路 1199

HDU 5175 Misaki's Kiss again(暴力枚举+异或运算)

题意 找到满足gcd(N,M)==NxorM的M值(1<=M<=N) 解析: 令M = N xor K,原式:gcd(N,N xor K) == N xor (N xor K) == K 由此我们可以发现K是N的约数,找到所有N的约数,判断是不是满足那个等式即可,因为是异或运算,结果可能比约数本身大,如1xor2==3,还有异或出来结果等于0的舍掉,gcd(n,n) != n xor

小G的ACM之路 1127
上一篇: HDU - 5033 Building(单调栈)
下一篇: UVA - 10714 Ants(贪心)
HelloWorld10086
博客等级 码龄12年 88粉丝 614原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值