Counterfeit Dollar -----判断12枚钱币中的一个假币
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u
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.
1 #include<iostream>
2 #include<cmath>
3 using namespace std;
4
5 int main(void)
6 {
7 int cases;
8 cin>>cases;
9 for(int c=1;c<=cases;c++)
10 {
11 char left[3][6],right[3][6],status[3][6];
12
13 int time['L'+1]={0}; //标记各个字母被怀疑的次数
14 bool zero['L'+1]={false}; //标记绝对为真币的字母(令天枰平衡的所有字母)
15
16 for(int k=0;k<3;k++)
17 cin>>left[k]>>right[k]>>status[k];
18
19 for(int i=0;i<3;i++)
20 {
21 switch(status[i][0]) //检查天枰状态
22 {
23 case 'u': //up,天枰左重右轻
24 {
25 for(int j=0;left[i][j];j++)
26 {
27 time[ left[i][j] ]++; //左重
28 time[ right[i][j] ]--; //右轻
29 }
30 break;
31 }
32 case 'd': //down,天枰左轻右重
33 {
34 for(int j=0;left[i][j];j++)
35 {
36 time[ left[i][j] ]--; //左轻
37 time[ right[i][j] ]++; //右重
38 }
39 break;
40 }
41 case 'e': //down,天枰平衡
42 {
43 for(int j=0;left[i][j];j++)
44 {
45 zero[ left[i][j] ]=true; //绝对真币
46 zero[ right[i][j] ]=true; //绝对真币
47 }
48 break;
49 }
50 }
51 }
52
53 int max=-1; //查找被怀疑程度最高的硬币(假币)
54 char alpha;
55 for(int j='A';j<='L';j++)
56 {
57 if(zero[j]) //绝对真币
58 continue;
59
60 if(max<=abs(time[j]))
61 {
62 max=abs(time[j]);
63 alpha=j;
64 }
65 }
66
67 cout<<alpha<<" is the counterfeit coin and it is ";
68 if(time[alpha]>0)
69 cout<<"heavy."<<endl;
70 else
71 cout<<"light."<<endl;
72 }
73 return 0;
74 }
Counterfeit Dollar -----判断12枚钱币中的一个假币的更多相关文章
- POJ 1013 Counterfeit Dollar
Counterfeit Dollar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 36206 Accepted: 11 ...
- POJ1013 Counterfeit Dollar
题目来源:http://poj.org/problem?id=1013 题目大意:有12枚硬币,其中有一枚假币.所有钱币的外表都一样,所有真币的重量都一样,假币的重量与真币不同,但我们不知道假币的重量 ...
- POJ 1013:Counterfeit Dollar
Counterfeit Dollar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42028 Accepted: 13 ...
- Counterfeit Dollar 分类: POJ 2015-06-12 15:28 19人阅读 评论(0) 收藏
Counterfeit Dollar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 41559 Accepted: 13 ...
- 1366 xth 的第 12 枚硬币
1366 xth 的第 12 枚硬币 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 传说 xth 曾 ...
- poj1013.Counterfeit Dollar(枚举)
Counterfeit Dollar Time Limit: 1 Sec Memory Limit: 64 MB Submit: 415 Solved: 237 Description Sally ...
- 高并发分布式系统中生成全局唯一(订单号)Id js返回上一页并刷新、返回上一页、自动刷新页面 父页面操作嵌套iframe子页面的HTML标签元素 .net判断System.Data.DataRow中是否包含某列 .Net使用system.Security.Cryptography.RNGCryptoServiceProvider类与System.Random类生成随机数
高并发分布式系统中生成全局唯一(订单号)Id 1.GUID数据因毫无规律可言造成索引效率低下,影响了系统的性能,那么通过组合的方式,保留GUID的10个字节,用另6个字节表示GUID生成的时间(D ...
- 九度OJ 1150:Counterfeit Dollar(假美元) (分析、检验)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:485 解决:215 题目描述: Sally Jones has a dozen Voyageur silver dollars. Howev ...
- xth的第 12 枚硬币(codevs 1366)
题目描述 Description 传说 xth 曾经拥有11枚完全相同硬币(你懂得),不过今年呢,rabbit又送了他一 枚硬币.这枚硬币和其他硬币外观相同,只有重量不同,或轻或重.Xth 一不小心, ...
随机推荐
- java中的jComBox的基本用法
jComBox获取选中的字符串 getSelectedItem().toString()返回一个字符串 getSelectedItem()返回一个对象. getSelectedIndex()得到选择值 ...
- BZOJ 1485: [HNOI2009]有趣的数列
Description 求长度为 \(2n\) 的序列.要求 1. \(a_1<a_3<a_5<...<a_{2n-1}\) . 2. \(a_2<a_4<a_6& ...
- jenkins Auth fail验证失败
重新设置密码
- scp和rsync限制传输速度
1.scp 限速100KB/s scp -l 1000 test root@192.168.1.104 此时的传输速率就是1M/8=100KB左右 2.rsync 限速100KB/s rsync -a ...
- jquery数组内多维对象
jquery数组内多维对象 var postData=[],obj,list; obj = !!obj ? obj : $('#dist_meici_checkinfo_form'); obj.fin ...
- 开始学习C++
这里突然想起来当初学习java和C# 总是会有个demo : hello world. 这里我记得我曾经看过一个笑话.说有个程序员,想学习书法,买了笔墨,都准备好了,但是不知道写什么好.最后,他大 ...
- hdu1520
基本的树形dp #include <cstring> #include <cstdio> #include <vector> using namespace std ...
- Qt字符转换
1.QString -> char* #include<QTextCodec> QTextCodec::setCodecForLocale(QTextCodec::codecFor ...
- delphi的取整函数round、trunc、ceil和floor
delphi的取整函数round.trunc.ceil和floor 首先引入math单元 uses math; 1.Round(四舍六入五留双) 功能说明:对一个实数进行四舍五入.(按照银行家算法) ...
- 1.SpringMVC的简介和环境搭建
SpringMVC的简介: SpringMVC 和 Struts一样是一个MVC框架,和Spring无缝连接,和struts2类似, Spring MVC属于SpringFrameWork的后续产品, ...