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

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
ABCD EFGH even
ABCI EFJK up
ABIJ EFGH even

Sample Output

K is the counterfeit coin and it is light. 
/*
不知道为什么abs()函数一用就CE ,无奈就只能改成这样
后来用c++交就没事了,G++硬伤
*/
#include <cstdio>
#include <string.h>
#include <cmath>
char s[3][3][13];
int a[12];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
for(int i=0; i<3; i++)
{
scanf("%s %s %s",s[i][0],s[i][1],s[i][2]);
}
memset(a,0,sizeof(a));
for(int i=0; i<3; i++)
{
int len=strlen(s[i][0]);
if(strcmp(s[i][2],"even")==0)
{
for(int j=0; j<len; j++)
{
a[s[i][0][j]-'A']=141;
a[s[i][1][j]-'A']=141;
}
}
else if(strcmp(s[i][2],"up")==0)
{
for(int j=0; j<len; j++)
{
if(a[s[i][0][j]-'A']!=141)//不要忘加判断
{
a[s[i][0][j]-'A']++;
}
if(a[s[i][1][j]-'A']!=141)
{
a[s[i][1][j]-'A']--;
}
}
}
else if(strcmp(s[i][2],"down")==0)
{ for(int j=0; j<len; j++)
{
if(a[s[i][0][j]-'A']!=141)
{
a[s[i][0][j]-'A']--;
}
if(a[s[i][1][j]-'A']!=141)
{
a[s[i][1][j]-'A']++;
}
}
}
}
int Max=0;
int flag=0;
for(int i=0; i<12; i++)
{
if(a[i]!=141)
{
if(Max<fabs(a[i]))//绝对值最大怀疑的次数最多就是假币
{
Max=fabs(a[i]);
flag=i;
}
}
}
if(a[flag]<=0)//还要判断轻重
printf("%c is the counterfeit coin and it is light.\n",flag+'A');
else
{
printf("%c is the counterfeit coin and it is heavy.\n",flag+'A');
}
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

Counterfeit Dollar 分类: POJ 2015-06-12 15:28 19人阅读 评论(0) 收藏的更多相关文章

  1. 【solr基础教程之九】客户端 分类: H4_SOLR/LUCENCE 2014-07-30 15:28 904人阅读 评论(0) 收藏

    一.Java Script 1.由于Solr本身可以返回Json格式的结果,而JavaScript对于处理Json数据具有天然的优势,因此使用JavaScript实现Solr客户端是一个很好的选择. ...

  2. Borg Maze 分类: POJ 2015-07-27 15:28 5人阅读 评论(0) 收藏

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9971   Accepted: 3347 Description The B ...

  3. PIE(二分) 分类: 二分查找 2015-06-07 15:46 9人阅读 评论(0) 收藏

    Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...

  4. POJ 1068 AC 2014-01-07 15:24 146人阅读 评论(0) 收藏

    POJ的题目都是英文的,所以,,,还是直接贴代码吧 #include<stdio.h> int main(){ int x,y,z; int n,nm,max; scanf("% ...

  5. 周赛-DZY Loves Chessboard 分类: 比赛 搜索 2015-08-08 15:48 4人阅读 评论(0) 收藏

    DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. cf 61E. Enemy is weak 树状数组求逆序数(WA) 分类: Brush Mode 2014-10-19 15:16 104人阅读 评论(0) 收藏

    #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> ...

  7. max_flow(Dinic) 分类: ACM TYPE 2014-09-02 15:42 94人阅读 评论(0) 收藏

    #include <cstdio> #include <iostream> #include <cstring> #include<queue> #in ...

  8. SQL 分组 加列 加自编号 自编号限定 分类: SQL Server 2014-11-25 15:41 283人阅读 评论(0) 收藏

    说明: (1)日期以年月形式显示:convert(varchar(7),字段名,120) , (2)加一列 (3)自编号: row_number() over(order by 字段名 desc) a ...

  9. SQL 按月统计(两种方式) 分类: SQL Server 2014-08-04 15:36 154人阅读 评论(0) 收藏

    (1)Convert 函数 select Convert ( VARCHAR(7),ComeDate,120) as Date ,Count(In_code) as 单数,Sum(SumTrueNum ...

随机推荐

  1. c语言的一些库

    1利用DEv编程的时候遇见sleep函数  ..注意S大写,并添加#include<windows.h>.

  2. ACM常用算法及练习(2)

    ACM常用算法及练习 知识类型 重要度 容易度 应掌握度 典型题 其他           数据结构(5) 链表 ★★☆ ★★★ ★★☆     栈 stack ★★★ ★★★ ★★★ HLoj120 ...

  3. 变形--矩阵 matrix()

    matrix() 是一个含六个值的(a,b,c,d,e,f)变换矩阵,用来指定一个2D变换,相当于直接应用一个[a b c d e f]变换矩阵.就是基于水平方向(X轴)和垂直方向(Y轴)重新定位元素 ...

  4. WEB-INF/views/menu/list.jsp (line: 26, column: 58) equal symbol expected

    根本原因是由于单引号和双引号的混乱使用导致的. 解决办法: 将双引号里面的双引号改成单引号: 单引号里面的双引号该成单引号. 我的问题好像又不是这样的,<c:forEach var=" ...

  5. 2013年各大小IT公司待遇

    2013年各大小IT公司待遇(初版   摘自好网)本人西电硕士,根据今年找工作的情况以及身边同学的汇总,总结各大公司的待遇如下,吐血奉献给各位学弟学妹,公司比较全,你想去的公司不在这里面,基本上是无名 ...

  6. demo15 AlertDialog

    Dialog dialog = new AlertDialog.Builder(this).setTitle("对话框").setMessage("this is msg ...

  7. Fresco源码解析 - DataSource怎样存储数据

    Fresco源码解析 - DataSource怎样存储数据 datasource是一个独立的 package,与FB导入的guava包都在同一个工程内 - fbcore. datasource的类关系 ...

  8. SQL Server安装完成后3个需要立即修改的配置选项(转载)

    你用安装向导安装了全新的SQL Server,最后你点击了完成按钮.哇噢~~~现在我们可以把我们的服务器进入生产了!抱歉,那并不是真的,因为你的全新SQL Server默认配置是错误的. 是的,你没看 ...

  9. 清除Cookie、获取指定Cookie的值、添加一个Cookie(24小时过期)、添加一个Cookie

    MXS&Vincene  ─╄OvЁ  &0000007 ─╄OvЁ  MXS&Vincene MXS&Vincene  ─╄OvЁ:今天很残酷,明天更残酷,后天很美好 ...

  10. 160921、React入门教程第一课--从零开始构建项目

    工欲善其事必先利其器,现在的node环境下,有太多好用的工具能够帮助我们更好的开发和维护管理项目. 我本人不建议什么功能都自己写,我比较喜欢代码复用.只要能找到npm包来实现的功能,坚决不自己敲代码. ...