1366 xth 的第 12 枚硬币

1366 xth 的第 12 枚硬币

 

 时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 钻石 Diamond
 
 
 
题目描述 Description

传说 xth 曾经拥有11枚完全相同硬币(你懂得),不过今年呢,rabbit又送了他一
枚硬币。这枚硬币和其他硬币外观相同,只有重量不同,或轻或重。Xth 一不小心,
将这枚特殊的硬币和其他硬币混在了一起。Rabbit 知道后很生气,要他立刻把那枚
硬币找出来,并且还要说出这枚硬币是轻还是重。可怜的 Xth 只有一架普通托盘天
平,并且只能称量三次(每次称量,两边各四枚)。现在全部 12枚硬币编号为
A~L,现给出你三次称量的结果,请你帮 xth 找出那枚不一样的硬币。他一定会感
谢你们滴~~~

输入描述 Input Description

共三行,每行是由空格隔开的两个字符串,分别代表左右两盘的四个硬币,以及一
个单词。’even’表示两侧重量相等,’up’表示右侧轻,’down’表示右侧重。

输出描述 Output Description

一行,一个英文句子,指出那枚不一样的硬币以及它的轻重情况。
X is the counterfeit coin and it is light/heavy. (X表示硬币)

样例输入 Sample Input

ABCD EFGH even 
ABCI EFJK up 
ABIJ EFGH even

样例输出 Sample Output

K is the counterfeit coin and it is light.

数据范围及提示 Data Size & Hint

数据保证有且仅有一枚特殊的硬币,无矛盾情况出现。

分类标签 Tags 点此展开 

 
题解:
直接模拟即可
找可能性最大的那个字母
AC代码:
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;
const int N=1e3+10;
string s[10];
short vis[N];
int main(){
    for(int i=1;i<=9;i++) cin>>s[i];
    for(int i=3;i<=9;i+=3){
        if(s[i]=="even"){
            for(int j=0;j<4;j++) vis[s[i-2][j]]=10000;
            for(int j=0;j<4;j++) vis[s[i-1][j]]=10000;
        }
        else if(s[i]=="up"){
            for(int j=0;j<4;j++) vis[s[i-2][j]]+=1;
            for(int j=0;j<4;j++) vis[s[i-1][j]]-=1;
        }
        else if(s[i]=="down"){
            for(int j=0;j<4;j++) vis[s[i-2][j]]-=1;
            for(int j=0;j<4;j++) vis[s[i-1][j]]+=1;
        }
    }//注意判断 
    for(int i='A';i<='Z';i++) if(vis[i]==-3){printf("%c is the counterfeit coin and it is light.
",i);return 0;}
    for(int i='A';i<='Z';i++) if(vis[i]==3){printf("%c is the counterfeit coin and it is heavy.
",i);return 0;}
    for(int i='A';i<='Z';i++) if(vis[i]==-2){printf("%c is the counterfeit coin and it is light.
",i);return 0;}
    for(int i='A';i<='Z';i++) if(vis[i]==2){printf("%c is the counterfeit coin and it is heavy.
",i);return 0;}
    for(int i='A';i<='Z';i++) if(vis[i]==-1){printf("%c is the counterfeit coin and it is light.
",i);return 0;}
    for(int i='A';i<='Z';i++) if(vis[i]==1){printf("%c is the counterfeit coin and it is heavy.
",i);return 0;}
    return 0;
}
原文地址:https://www.cnblogs.com/shenben/p/5922855.html