1366 xth 的第 12 枚硬币
2016-09-30 10:07
204 查看
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 点此展开
字符串处理[b]题解:[/b]
直接模拟即可
找可能性最大的那个字母
[b]AC代码:[/b]
#include<cstdio> #include<string> #include<iostream> using namespace std; const int N=1e3+10; string s[10]; short vis ; 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; }
相关文章推荐
- xth的第 12 枚硬币(codevs 1366)
- 12球问题/12硬币问题通解,以及引申的决策树/最优三叉树算法
- 12硬币中有一个不知道轻重的假币,用天平将它找出来
- 平均需要扔多少次硬币才能够得到连续2个正面 [# 12]
- C#学习日志(12)
- C#开发微信门户及应用(12)-使用语音处理
- 12 个非常实用的 jQuery 代码片段
- 【SDOI2017】硬币游戏
- 算法提高 12-2扑克排序
- zeroMQ初体验-12.安全与稳定
- 12 很有用的 Chrome 浏览器命令
- 深入分析JavaWeb 12 -- jsp运行原理与基本语法
- Android从零开搞系列:自定义View(12)贝塞尔曲线的应用
- FVC/JEM代码学习12:transformNxN
- 12 很有用的 Chrome 浏览器命令
- 分支-12. 计算火车运行时间(15)
- SQL Server代理(7/12):作业活动监视器
- 12、springboot注解
- Wannafly挑战赛12 B T95要减肥【DP】
- Exadata X2-2 vs EMC Greenplum DCA vs Netezza TwinFin 12主要配置大对比