uva 340 A - Master-Mind Hints (暴力)

A - Master-Mind Hints

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Submit Status

Description

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.

match is a pair (i,j),  and  , such that  . Match (i,j) is called strong when i = j, and is called weak otherwise. Two matches (i,j) and (p,q) are called independent when 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 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 for N 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.

给定一个答案序列.

之后给定若干个相同长度的序列

问有多少位置对应的数字相同,以及数字相同,但位置不对应的位置的个数.(位置的意思是,如果不同的位置出现相同的数字,那么要算多次)

前者扫一遍就可以得到结果,答案记为ans1

后者我们可以先考虑在两个序列中都出现的数字的个数,再减去ans1

 1 /*************************************************************************
 2     > File Name: code/uva/340.cpp
 3     > Author: 111qqz
 4     > Email: [email protected]
 5     > Created Time: 2015年09月15日 星期二 16时19分44秒
 6  ************************************************************************/
 7
 8 #include<iostream>
 9 #include<iomanip>
10 #include<cstdio>
11 #include<algorithm>
12 #include<cmath>
13 #include<cstring>
14 #include<string>
15 #include<map>
16 #include<set>
17 #include<queue>
18 #include<vector>
19 #include<stack>
20 #include<cctype>
21 #define y1 hust111qqz
22 #define yn hez111qqz
23 #define j1 cute111qqz
24 #define ms(a,x) memset(a,x,sizeof(a))
25 #define lr dying111qqz
26 using namespace std;
27 #define For(i, n) for (int i=0;i<int(n);++i)
28 typedef long long LL;
29 typedef double DB;
30 const int inf = 0x3f3f3f3f;
31 const int N=1E3+7;
32 int n;
33 int a[N],b[N];
34 int cnt1,cnt2,ans1,ans2,ans;
35
36 int main()
37 {
38   #ifndef  ONLINE_JUDGE
39     freopen("in.txt","r",stdin);
40   #endif
41     int cas = 0 ;
42     while (scanf("%d",&n)!=EOF&&n)
43     {
44     cas++;
45     printf("Game %d:\n",cas);
46     for ( int i = 0 ; i < n ; i++)
47         scanf("%d",&a[i]);
48
49
50     int x;
51     while (scanf("%d",&x)!=EOF)
52     {
53         ans1 = 0 ;
54         ans2 = 0 ;
55         ans = 0;
56         b[0] = x;
57         for ( int i = 1 ; i < n  ; i++)
58         scanf("%d",&b[i]);
59         if (x==0) break; //注意要都读完再break掉....傻逼错误多少次了
60
61         for (int i = 0 ; i < n ; i++)
62         if (a[i]==b[i])
63             ans1++;
64
65
66
67
68         for ( int dig = 1 ; dig <= 9 ; dig++)
69         {
70         cnt1 = 0 ;
71         cnt2 = 0;
72         for (int i = 0 ; i < n ; i++)
73         {
74             if (a[i]==dig) cnt1++;
75             if (b[i]==dig) cnt2++;
76         }
77         int MIN = min(cnt1,cnt2);
78         ans2 = ans2 + MIN;
79         }
80         printf("    (%d,%d)\n",ans1,ans2-ans1);
81
82     }
83     }
84
85
86  #ifndef ONLINE_JUDGE
87   fclose(stdin);
88   #endif
89     return 0;
90 }

时间: 2024-10-12 02:22:15

uva 340 A - Master-Mind Hints (暴力)的相关文章

UVa 340 Master-Mind Hints

蛋疼的题目描述,看了好长好长时间才看懂,题目本身是很简单的. Designer给出一串长度为N的Code,Breaker用Guess来破译. 对于两串数字,如果有同一列相等的数字,那么叫做strong  match, 位于不同列的相等的两个数字,叫做weak  match. 题目要求就是先输出strong的个数,然后是weak的个数. 对了,需要注意的是 1.每个code只能匹配一次,不论是strong还是match. 2.输出(*,*)的时候注意前面那四个空格,就因为这个我还PE了一次. 如果

UVA 532 Dungeon Master

题目如下: Dungeon Master  You are trapped in a 3D dungeon and need to find the quickest way out!The dungeon is composedof unit cubes which may or may not be filled with rock. It takes one minuteto move one unit north,south, east, west, up or down. You ca

UVA 152-Tree&#39;s a Crowd(暴力求解三维坐标求最短距离)

Tree's a Crowd Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description  Tree's a Crowd  Dr William Larch, noted plant psychologist and inventor of the phrase ``Think like a tree--Think Fig'' has invented a new

uva 639 Don&#39;t Get Rooked (暴力回溯 )

uva 639 Don't Get Rooked In chess, the rook is a piece that can move any number of squares vertically or horizontally. In this problem we will consider small chess boards (at most 44) that can also contain walls through which rooks cannot move. The g

uva 11754 - Code Feat(中国剩余定理+暴力)

题目链接:uva 11754 - Code Feat 题目大意:求一个数N,给出C和S,表示有C个条件,每个条件有X 和 k,然后是该个条件的k个yi,即NmodX=yj,输出满足的最小的S个N,要求正整数. 解题思路:total为所有的k的乘积,也就是可以作为一组完整限定条件的可能数,当个确定条件可以用中国剩余定理处理.但是如果total太大的话,处理的情况比较多.不过total数大的时候,可以通过枚举N来判断,找到一组k/x最小的最为枚举基准,然后判断即可. #include <cstdio

uva 1069 - Always an integer(数学+暴力)

题目链接:uva 1069 - Always an integer 题目大意:给出一个多次多项式,问说是否对于任意正整数n来说结构均为整数. 解题思路:首先处理出字符串,然后枚举n从1到k+1判断即可,k为多项式中出现过的最大幂数指. P为多项式,d为除数,k为多项式中最大的次数 当k=0时,P中不存在n变量,所以直接计算判断即可 当k=1时,P是一次多项式,那么P(n+1)?P(n)=a,a为常数,也就是说P(i)为等差数列,如果首项P(1)和公差P(2)-P(1)为d的倍数即可,等价与判断P

UVA 617 - Nonstop Travel(数论+暴力枚举)

题目链接:617 - Nonstop Travel 题意:给定一些红绿灯,现在速度能在30-60km/h之内,求多少个速度满足一路不遇到红灯. 思路:暴力每一个速度,去判断可不可以,最后注意下输出格式即可 代码: #include <stdio.h> #include <string.h> #include <math.h> const double esp = 1e-6; int n, vis[105]; struct D { double l; int g, y,

uva 532 Dungeon Master(BFS)

uva 532 Dungeon Master You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. Y

猜数字游戏的提示(Master-Mind Hints , UVa 340)

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