H - Counterfeit Dollar
来源:互联网 发布:百年孤独中的女性 知乎 编辑:程序博客网 时间:2024/06/03 07:34
Description
Happily, Sally has a friend who loans her a very accurate balance scale. The friend will permit Sally three weighings to find the counterfeit coin. For instance, if Sally weighs two coins against each other and the scales balance then she knows these two coins are true. Now if Sally weighs
one of the true coins against a third coin and the scales do not balance then Sally knows the third coin is counterfeit and she can tell whether it is light or heavy depending on whether the balance on which it is placed goes up or down, respectively.
By choosing her weighings carefully, Sally is able to ensure that she will find the counterfeit coin with exactly three weighings.
Input
Output
Sample Input
1 ABCD EFGH even ABCI EFJK up ABIJ EFGH even
Sample Output
K is the counterfeit coin and it is light.
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#define MAX 1000005
using namespace std;
int main()
{
int n;
cin>>n;
int coin[26];//若等于10则说明是真的硬币
char left[13],right[13],status[5];
while(n--)
{
memset(coin,0,sizeof(coin));
for(int i=0;i<3;i++)
{
scanf("%s%s%s",left,right,status);
int length=strlen(left);
if(strcmp(status,"even")==0)
{
for(int j=0;j<length;j++)
{
coin[left[j]-'A']=10;
coin[right[j]-'A']=10;
}
}
else if(strcmp(status,"up")==0)
{
for(int j=0;j<length;j++)
{
if(coin[left[j]-'A']!=10)
coin[left[j]-'A']++;
if(coin[right[j]-'A']!=10)
coin[right[j]-'A']--;
}
}
else if(strcmp(status,"down")==0)
{
for(int j=0;j<length;j++)
{
if(coin[left[j]-'A']!=10)
coin[left[j]-'A']--;
if(coin[right[j]-'A']!=10)
coin[right[j]-'A']++;
}
}
}
int max=0,k;
for(int i=0;i<12;i++)
{
if(coin[i]==10)
continue;
if(max<=abs(coin[i])){
max=abs(coin[i]);
k=i;
}
}
if(coin[k]<0)
printf("%c is the counterfeit coin and it is light.\n",'A'+k);
else printf("%c is the counterfeit coin and it is heavy.\n",'A'+k);
}
return 0;
}
- H - Counterfeit Dollar
- Counterfeit Dollar
- Counterfeit Dollar
- Counterfeit Dollar
- Counterfeit Dollar
- Counterfeit Dollar
- Counterfeit Dollar
- Counterfeit Dollar
- Counterfeit Dollar
- Counterfeit Dollar
- Counterfeit Dollar
- Counterfeit Dollar
- Counterfeit Dollar
- POJ 1013 Counterfeit Dollar
- 1013 Counterfeit Dollar
- pku_1013 Counterfeit Dollar
- POJ 1013 Counterfeit Dollar
- FOJ 1003 Counterfeit Dollar
- Hadoop集群集成kerberos
- 正则表达式
- 各种分布式文件系统简介
- mongodb的启动与关闭
- Java集合中那些类是线程安全的
- H - Counterfeit Dollar
- sublime记录
- $query语法基础
- 润乾报表-数据集函数
- eclipse资源文件搜索如何去掉class文件
- 为何将构造函数定义为private,protected?
- IOS中http请求使用cookie
- C/C++函数模板template
- HIVE查询