Counterfeit Dollar

Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are true silver dollars; one coin is counterfeit even though its color and size make it indistinguishable from the real silver dollars. The counterfeit coin has a different weight from the other coins but Sally does not know if it is heavier or lighter than the real coins. 
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

The first line of input is an integer n (n > 0) specifying the number of cases to follow. Each case consists of three lines of input, one for each weighing. Sally has identified each of the coins with the letters A--L. Information on a weighing will be given by two strings of letters and then one of the words ``up'', ``down'', or ``even''. The first string of letters will represent the coins on the left balance; the second string, the coins on the right balance. (Sally will always place the same number of coins on the right balance as on the left balance.) The word in the third position will tell whether the right side of the balance goes up, down, or remains even.

Output

For each case, the output will identify the counterfeit coin by its letter and tell whether it is heavy or light. The solution will always be uniquely determined.

Sample Input

  1. 1
  2. ABCD EFGH even
  3. ABCI EFJK up
  4. ABIJ EFGH even

Sample Output

  1. K is the counterfeit coin and it is light.
  1. 1 #include<iostream>
  2. 2 #include<cmath>
  3. 3 using namespace std;
  4. 4
  5. 5 int main(void)
  6. 6 {
  7. 7 int cases;
  8. 8 cin>>cases;
  9. 9 for(int c=1;c<=cases;c++)
  10. 10 {
  11. 11 char left[3][6],right[3][6],status[3][6];
  12. 12
  13. 13 int time['L'+1]={0}; //标记各个字母被怀疑的次数
  14. 14 bool zero['L'+1]={false}; //标记绝对为真币的字母(令天枰平衡的所有字母)
  15. 15
  16. 16 for(int k=0;k<3;k++)
  17. 17 cin>>left[k]>>right[k]>>status[k];
  18. 18
  19. 19 for(int i=0;i<3;i++)
  20. 20 {
  21. 21 switch(status[i][0]) //检查天枰状态
  22. 22 {
  23. 23 case 'u': //up,天枰左重右轻
  24. 24 {
  25. 25 for(int j=0;left[i][j];j++)
  26. 26 {
  27. 27 time[ left[i][j] ]++; //左重
  28. 28 time[ right[i][j] ]--; //右轻
  29. 29 }
  30. 30 break;
  31. 31 }
  32. 32 case 'd': //down,天枰左轻右重
  33. 33 {
  34. 34 for(int j=0;left[i][j];j++)
  35. 35 {
  36. 36 time[ left[i][j] ]--; //左轻
  37. 37 time[ right[i][j] ]++; //右重
  38. 38 }
  39. 39 break;
  40. 40 }
  41. 41 case 'e': //down,天枰平衡
  42. 42 {
  43. 43 for(int j=0;left[i][j];j++)
  44. 44 {
  45. 45 zero[ left[i][j] ]=true; //绝对真币
  46. 46 zero[ right[i][j] ]=true; //绝对真币
  47. 47 }
  48. 48 break;
  49. 49 }
  50. 50 }
  51. 51 }
  52. 52
  53. 53 int max=-1; //查找被怀疑程度最高的硬币(假币)
  54. 54 char alpha;
  55. 55 for(int j='A';j<='L';j++)
  56. 56 {
  57. 57 if(zero[j]) //绝对真币
  58. 58 continue;
  59. 59
  60. 60 if(max<=abs(time[j]))
  61. 61 {
  62. 62 max=abs(time[j]);
  63. 63 alpha=j;
  64. 64 }
  65. 65 }
  66. 66
  67. 67 cout<<alpha<<" is the counterfeit coin and it is ";
  68. 68 if(time[alpha]>0)
  69. 69 cout<<"heavy."<<endl;
  70. 70 else
  71. 71 cout<<"light."<<endl;
  72. 72 }
  73. 73 return 0;
  74. 74 }

Counterfeit Dollar -----判断12枚钱币中的一个假币的更多相关文章

  1. POJ 1013 Counterfeit Dollar

    Counterfeit Dollar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36206   Accepted: 11 ...

  2. POJ1013 Counterfeit Dollar

    题目来源:http://poj.org/problem?id=1013 题目大意:有12枚硬币,其中有一枚假币.所有钱币的外表都一样,所有真币的重量都一样,假币的重量与真币不同,但我们不知道假币的重量 ...

  3. POJ 1013:Counterfeit Dollar

    Counterfeit Dollar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42028   Accepted: 13 ...

  4. Counterfeit Dollar 分类: POJ 2015-06-12 15:28 19人阅读 评论(0) 收藏

    Counterfeit Dollar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 41559   Accepted: 13 ...

  5. 1366 xth 的第 12 枚硬币

    1366 xth 的第 12 枚硬币  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 传说 xth 曾 ...

  6. poj1013.Counterfeit Dollar(枚举)

    Counterfeit Dollar Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 415  Solved: 237 Description Sally ...

  7. 高并发分布式系统中生成全局唯一(订单号)Id js返回上一页并刷新、返回上一页、自动刷新页面 父页面操作嵌套iframe子页面的HTML标签元素 .net判断System.Data.DataRow中是否包含某列 .Net使用system.Security.Cryptography.RNGCryptoServiceProvider类与System.Random类生成随机数

    高并发分布式系统中生成全局唯一(订单号)Id   1.GUID数据因毫无规律可言造成索引效率低下,影响了系统的性能,那么通过组合的方式,保留GUID的10个字节,用另6个字节表示GUID生成的时间(D ...

  8. 九度OJ 1150:Counterfeit Dollar(假美元) (分析、检验)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:485 解决:215 题目描述: Sally Jones has a dozen Voyageur silver dollars. Howev ...

  9. xth的第 12 枚硬币(codevs 1366)

    题目描述 Description 传说 xth 曾经拥有11枚完全相同硬币(你懂得),不过今年呢,rabbit又送了他一 枚硬币.这枚硬币和其他硬币外观相同,只有重量不同,或轻或重.Xth 一不小心, ...

随机推荐

  1. mysql日期加减<转>

    1. MySQL 为日期增加一个时间间隔:date_add() set @dt = now(); select date_add(@dt, interval 1 day); - 加1天 select ...

  2. 35 网络相关函数(三)——live555源码阅读(四)网络

    35 网络相关函数(三)——live555源码阅读(四)网络 35 网络相关函数(三)——live555源码阅读(四)网络 简介 5)NoReuse不重用地址类 6)initializeWinsock ...

  3. jQuery操作checkbox实例

    示意图 <script type="text/javascript"> $(function () { $("#ddlNumber").change ...

  4. midi格式

    http://www.ccarh.org/courses/253/handout/smf/

  5. shell脚本实现拷贝大文件显示百分比的代码分享

    #!/bin/sh strace -q -eread cp -- "${1}" "${2}" 2>&1 \| awk '{    count += ...

  6. 一步步搭建docker私有仓库并从私有仓库中下载镜像

    一步步搭建docker私有仓库 #下载镜像 docker pull registry#查看镜像 docker images #运行私有仓库,指定端口和数据卷 docker run -d -p : -v ...

  7. 基础01 dos命令

    常见的dos命令: 盘符:        进入指定的盘下面. 操作文件夹:                   dir                                   列出当前控制 ...

  8. Delphi TcxCurrencyEditt控件说明

    金额类控件说明: AlignWithMargins:是否显示边框.由Margins 属性来设置边框的值 Anchors:控件停靠,来处理窗口最大化或是调动里的位置 AutoSize:是否自动变化大小 ...

  9. ACM/ICPC 之 并查集-食物链(POJ1182)

    并查集的经典题型,POJ上题目还是中文= =,一般看到中文题都会感觉不太简单,这道题的数学归纳用得比较多,可以简化代码,挺有意思的. 同类型的题目还有POJ1703,比这个要简单,想了解并查集基本介绍 ...

  10. 10. javacript高级程序设计-DOM

    1. DOM DOM(文档对象模型)是针对HTML和XML文档的一个API(应用程序接口) 1.1 节点层次 DOM可以将任何HTML和XML文档描绘成一个由多层节点构成的结构.节点分为几种不同的类型 ...