# UVa-340 - Master-Mind Hints

2016/6/4重刷

#include <map>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
freopen("in1.txt","r",stdin);
int N;
int Game=1;
while(scanf("%d",&N)==1 && N)
{
int n;
int A,B,F;
string S="",S1;
for(int i=0; i<N; i++){
scanf("%d",&n);
S+='0'+n;
}
//cout<<"The S is "<<S<<endl;
printf("Game %d:\n",Game++);
while(1){
A=0,B=0,F=1;
S1="";
for(int i=0; i<N; i++){
scanf("%d",&n);
S1+='0'+n;
if(n!=0) F=0;
}
if(F) break;
//cout<<"The S1 is "<<S1<<endl;
int a[10];
int b[10];
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(int i=0; i<S.size(); i++){
if(S[i]==S1[i]) { A++; }
else{
a[S[i]-'0']++;
b[S1[i]-'0']++;
}
}
for(int i=0; i<10; i++)
{
//cout<<a[i]<<" "<<b[i]<<endl;
if(a[i]&&b[i])
B+=(a[i]>b[i] ? b[i] : a[i]);
}
printf("    (%d,%d)\n",A,B);
}
}
return 0;
}


min(c1,c2)就是该数字对B的贡献，最终 B的值等于在两个序列中都出现的 公共数字的个数，再减去A的部分，即得最终要求的B。

#include<iostream>
#include<cstdio>
#include<cstring>
//#define LOCAL
using namespace std;
#define maxn 1024
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int n, game=0;
int a[maxn],b[maxn];
while(scanf("%d",&n)==1&&n)
{
for(int i=0; i<n; i++) scanf("%d",&a[i]);//secret code
int A=0,B=0;
printf("Game %d:\n",++game);
while(1){
A=0;B=0;
for(int i=0;i<n; i++){
scanf("%d",&b[i]);
if(a[i]==b[i]) A++;
}
if(b[0]==0) break;
for(int j=1; j<=9; j++){
int c1=0,c2=0;
for(int k=0; k<n; k++){
if(a[k]==j)c1++;
if(b[k]==j)c2++;
}
if(c1<c2) B+=c1; else B+=c2;
}
printf("    (%d,%d)\n",A,B-A);
}
}
return 0;
}

• 本文已收录于以下专栏：

## UVA 340 Master-Mind Hints

Master-Mind Hints Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & ...

## UVa 340 - Master-Mind Hints

Master-Mind Hints  MasterMind is a game for two players. One of them, Designer, selects a...

## uva 340 -----Master-Mind Hints（猜数字游戏的提示）

MasterMind is a game for two players. One of them, Designer, selects a secret code. The other, Break...

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

• acvay
• 2014-08-31 09:20
• 833

## 章三例题4——UVA 340 Master -Mind Hints

Master-Mind Hints MasterMind is a game for two players. One of them, Designer, selects a secret cod...

## UVA - 340 Master-Mind Hints

Master-Mind Hints Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

## uva340 - Master-Mind Hints

MasterMind is a game for two players. One of them, Designer, selects a secret code. The other,Breake...

## UVa 340 Master-Mind Hints

Master-Mind Hints  MasterMind is a game for two players. One of them, Designer, selects...

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)