UVa340 Master-Mind Hints
2013-07-31 20:40
393 查看
Master-Mind Hints |
Breaker, tries to break it. A code is no morethan a row of colored dots. At the beginning of a game, the playersagree upon the length
N that a code must have and upon the colors thatmay occur in a code.
In order to break the code, Breaker makes anumber of guesses, each guess itself being a code. After each guessDesigner gives a hint, stating to what extent the guess matches hissecret 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
strong when i = j, and is called weakotherwise. Two matches (i,j) and (p,q) are called
independentwhen i = 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 ofmatches and the number of strong matches are both maximal. The hintthen consists of the number of strong followed by the number of weakmatches in
M. Note that these numbers are uniquely determined by thesecret code and the guess. If the hint turns out to be (n,0), then theguess 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 specifyingN (the lengthof the code). Following these will be the secret code, representedas
N integers, which we will limit to the range 1 to 9. There will thenfollow an arbitrary number of guesses, each also represented as
Nintegers, each in the range 1 to 9. Following the last guess in eachgame will be
N zeroes; these zeroes are not to be considered as a guess.
Following the data for the first game will appear data forthe second game (if any) beginning with a new value for
N. The lastgame in the input will be followed by a single zero (when a value for
Nwould normally be specified). The maximum value for N will be 1000.
Output
The output for each game should list the hints thatwould be generated for each guess, in order, one hint per line. Eachhint should be represented as a pair of integers enclosed in parentheses and separated by a comma. The entire list of hints for each gameshouldbe prefixed by a heading indicating the game number; games arenumbered 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)
题目大意是有一种猜数字游戏,假设有A,B两个人,首先是A选定n位数字,然后B开始猜测,B每次猜测后,A将对此次猜测进行评价(p,q),p为数字正确且位置正确的个数,q为仅数字正确的个数,且p的优先级大于q,当结果为(n,0)时就表示完全猜中,然后是以n个0来结束。
#include <iostream>
#include <cstring>
using namespace std;
const int N = 1100;
int a
;
int b
;
bool c
;
int main() {
int len;
int Case = 1;
while (cin >> len) {
if (!len)
break;
for (int i = 0; i < len; i++)
cin >> a[i];
bool t = true;
while (1) {
for (int j = 0; j < len; j++)
cin >> b[j];
if (!b[0])
break;
if (t) {
cout << "Game " << Case << ":" << endl;
Case++;
t = false;
}
int x = 0;
int y = 0;
memset(c,true,sizeof(c));
for (int j = 0; j < len; j++) {
if (a[j] == b[j]) {
b[j] = -1;
c[j] = false;
x++;
}
}
for (int j = 0; j < len; j++) {
if (c[j]) {
for (int k = 0; k < len; k++) {
if (a[j] == b[k]) {
b[k] = -1;
c[j] = false;
y++;
}
}
}
}
cout << " (" << x << "," << y << ")" << endl;
}
}
return 0;
}
相关文章推荐
- UVA-340 Master-Mind Hints
- UVa 340 Master-Mind Hints
- uva_340 - Master-Mind Hints
- UVa 340 - Master-Mind Hints
- UVa 340 Master-Mind Hints(猜数字游戏的提示)
- Uva - 340 - Master-Mind Hints
- 章三例题4——UVA 340 Master -Mind Hints
- UVA - 340 Master-Mind Hints
- UVA 340 Master-Mind Hints
- UVA 340 --Master-Mind Hints 算是模拟吧
- UVa 340 Master-Mind Hints
- UVa 340 - Master-Mind Hints
- Uva - 340 - Master-Mind Hints
- 章三例题4——UVA 340 Master -Mind Hints
- 【Uva 340】 Master-Mind Hints
- UVa340 Master-Mind Hints
- UVA - 340 Master-Mind Hints
- UVA-340 Master-Mind Hints
- uva340 - Master-Mind Hints
- UVA 340 - Master-Mind Hints 简单题 题面难看