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.\n",i);return 0;}
    for(int i='A';i<='Z';i++) if(vis[i]==3){printf("%c is the counterfeit coin and it is heavy.\n",i);return 0;}
    for(int i='A';i<='Z';i++) if(vis[i]==-2){printf("%c is the counterfeit coin and it is light.\n",i);return 0;}
    for(int i='A';i<='Z';i++) if(vis[i]==2){printf("%c is the counterfeit coin and it is heavy.\n",i);return 0;}
    for(int i='A';i<='Z';i++) if(vis[i]==-1){printf("%c is the counterfeit coin and it is light.\n",i);return 0;}
    for(int i='A';i<='Z';i++) if(vis[i]==1){printf("%c is the counterfeit coin and it is heavy.\n",i);return 0;}
    return 0;
}

 

转载于:https://www.cnblogs.com/shenben/p/5922855.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值