UVa 340 Master-Mind Hints(猜数字游戏的提示)
题意 猜数字游戏 统计猜的数字有多少个数字位置正确 有多少个数字在答案中出现可是位置不对 每一个字符仅仅能匹配一次
直接匹配每位数
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
const int N = 1005;
int a[N], b[N], c, d;
int main()
{
int n, cas = 0;
while (scanf ("%d", &n), n)
{
map<int, int> aa;
printf ("Game %d:\n", ++cas);
for (int i = 0; i < n; ++i)
{
scanf ("%d", &a[i]);
++aa[a[i]];
}
while (1)
{
map<int, int> bb;
for (int i = c = d = 0; i < n; ++i)
{
scanf ("%d", &b[i]);
++bb[b[i]];
if (a[i] == b[i]) c++;
}
if (!b[0]) break;
for (int i = 1; i <= 9; ++i)
d += min (aa[i], bb[i]);
printf (" (%d,%d)\n", c, d - c);
}
}
return 0;
}
Master-Mind Hints |
MasterMind is a game for two players. One of them, Designer, selects a secret code. The other,Breaker, tries to break it. A code is no more than a row of colored dots. At the beginning of a game, the players agree upon the length N that
a code must have and upon the colors that may occur in a code.
In order to break the code, Breaker makes a number of guesses, each guess itself being a code. After each guess Designer gives a hint, stating to what extent the guess matches his secret code.
In this problem you will be given a secret code and a guess ,
and are to determine the hint. A hint consists of a pair of numbers determined as follows.
A match is a pair (i,j), and ,
such that . Match (i,j) is called strongwhen i = j,
and is called weak otherwise. Two matches (i,j) and (p,q) are called independent wheni = p if and only if j = q. A set of matches is called independent when
all of its members are pairwise independent.
Designer chooses an independent set M of matches for which the total number of matches and the number of strong matches are both maximal. The hint then consists of the number of strong followed by the number of weak matches in M.
Note that these numbers are uniquely determined by the secret code and the guess. If the hint turns out to be (n,0), then the guess is identical to the secret code.
Input
The input will consist of data for a number of games. The input for each game begins with an integer specifying N (the length of the code). Following these will be the secret code, represented as N integers, which we will limit
to the range 1 to 9. There will then follow an arbitrary number of guesses, each also represented as N integers, each in the range 1 to 9. Following the last guess in each game will be N zeroes; these zeroes are not to be considered as a
guess.
Following the data for the first game will appear data for the second game (if any) beginning with a new value for N. The last game in the input will be followed by a single zero (when a value forN would normally be specified).
The maximum value for N will be 1000.
Output
The output for each game should list the hints that would be generated for each guess, in order, one hint per line. Each hint should be represented as a pair of integers enclosed in parentheses and separated by a comma. The entire list of hints
for each game should be prefixed by a heading indicating the game number; games are numbered sequentially starting with 1. Look at the samples below for the exact format.
Sample Input
4
1 3 5 5
1 1 2 3
4 3 3 5
6 5 5 1
6 1 3 5
1 3 5 5
0 0 0 0
10
1 2 2 2 4 5 6 6 6 9
1 2 3 4 5 6 7 8 9 1
1 1 2 2 3 3 4 4 5 5
1 2 1 3 1 5 1 6 1 9
1 2 2 5 5 5 6 6 6 7
0 0 0 0 0 0 0 0 0 0
0
Sample Output
Game 1:
(1,1)
(2,0)
(1,2)
(1,2)
(4,0)
Game 2:
(2,4)
(3,2)
(5,0)
(7,0)
UVa 340 Master-Mind Hints(猜数字游戏的提示)的更多相关文章
- [C++]猜数字游戏的提示(Master-Mind Hints,UVa340)
[本博文非博主原创,思路与题目均摘自 刘汝佳<算法竞赛与入门经典(第2版)>] Question 例题3-4 猜数字游戏的提示(Master-Mind Hints,UVa340) 实现一个 ...
- 猜数字游戏的提示(Master-Mind Hints, UVa 340)
实现一个经典"猜数字"游戏. 给定答案序列和用户猜的序列,统计有多少数字位置正确 (A),有多少数字在两个序列都出现过但位置不对(B). 输入包含多组数据.每组输入第一行为序列长度 ...
- 例题3_4 猜数字游戏的提示(UVa340)
实现一个经典“猜数字”游戏.给定答案序列和用户猜的序列,统计有多少数字位置正确(A),有多少数字在两个序列都出现过但位置不对(B). 输入包含多组数据.每组输入第一行为序列长度n,第二行是答案序列,接 ...
- 猜数字游戏的提示(UVa340)
题目具体描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_prob ...
- C语言猜数字游戏
猜数字游戏,各式各样的实现方式,我这边提供一个实现方式,希望可以帮到新手. 老程序猿就不要看了,黑呵呵 源代码1 include stdio.h include stdlib.h include ti ...
- 不一样的猜数字游戏 — leetcode 375. Guess Number Higher or Lower II
好久没切 leetcode 的题了,静下心来切了道,这道题比较有意思,和大家分享下. 我把它叫做 "不一样的猜数字游戏",我们先来看看传统的猜数字游戏,Guess Number H ...
- java 猜数字游戏
作用:猜数字游戏.随机产生1个数字(1~10),大了.小了或者成功后给出提示. 语言:java 工具:eclipse 作者:潇洒鸿图 时间:2016.11.10 >>>>> ...
- 【原创Android游戏】--猜数字游戏Version 0.1
想当年高中时经常和小伙伴在纸上或者黑板上或者学习机上玩猜数字的游戏,在当年那个手机等娱乐设备在我们那还不是很普遍的时候是很好的一个消遣的游戏,去年的时候便写了一个Android版的猜数字游戏,只是当时 ...
- 【原创Android游戏】--猜数字游戏V1.1 --数据存储,Intent,SimpleAdapter的学习与应用
--------------------------------------------------------------- V0.1版本 上次做完第一个版本后,发现还有一些漏洞,并且还有一些可以添 ...
随机推荐
- c++通过管道pipe获取cmd输出的字符
#include <stdio.h>#include<iostream>#include<string>using namespace std; // 描述:exe ...
- PHP常量和数据类型考察点
PHP 常量 常量是单个值的标识符(名称).在脚本中无法改变该值. 有效的常量名以字符或下划线开头(常量名称前面没有 $ 符号). 注释:与变量不同,常量贯穿整个脚本是自动全局的. PHP常量的两种定 ...
- Code::Blocks使用与调试一条龙
CodeBlocks创建C语言工程版本13.12 选择"create a new project" 选择第四个,点击"go" 4 选择"C&quo ...
- Ajax请求WebService跨域问题
1.背景 用Jquery中Ajax方式在asp.net开发环境中WebService接口的调用 2.出现的问题 原因分析:浏览器同源策略的影响(即JavaScript或Cookie只能访问同域下的内容 ...
- CREATE CONVERSION - 定义一个用户定义的码制转换
SYNOPSIS CREATE [DEFAULT] CONVERSION name FOR source_encoding TO dest_encoding FROM funcname DESCRIP ...
- 常见的HTTP相应状态码
200:请求被正常处理204:请求被受理但没有资源可以返回206:客户端只是请求资源的一部分,服务器只对请求的部分资源执行GET方法,相应报文中通过Content-Range指定范围的资源.301:永 ...
- vue脚手架引入swiper
方法一: 下载swiper: npm install swiper --save-dev swiper4.0使用入口:http://www.swiper.com.cn/usage/index.html ...
- 【JavaScript从入门到精通】第一课
第一课 初探JavaScript魅力-01 JavaScript是什么 如今我们打开一个大型的网站,都会有很多JS效果的功能和应用.对于学过CSS+HTML的同学,即使是像淘宝那样的网站,用一两天时间 ...
- day02 python函数基础
'''''''''列表: 定义: 在[]内,可以存放多个任意类型的值, 并以逗号隔开. 一般用于存放学生的爱好,课堂的周期等等...'''# 定义一个学生列表,可存放多个学生# list(['钱垚', ...
- Bzoj4899 记忆的轮廓
B. 记忆的轮廓 题目描述 通往贤者之塔的路上,有许多的危机.我们可以把这个地形看做是一颗树,根节点编号为1,目标节点编号为n,其中1-n的简单路径上,编号依次递增,在[1,n]中,一共有n个节点.我 ...