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. 如何在RedHat6(7) or CentOS6(7)上制作无依赖的PostgreSQL数据库的RPM包

    本文解决了源代码安装都需要先检查系统上是否安装了应用程序所依赖的软件包的烦恼,对源代码开发者也有一定的帮助.可以在该基础上进行适当的修改,以满足自己的要求. RedHat5 or CentOS5已经提 ...

  2. 转:Busy Developers' Guide to HSSF and XSSF Features

    Busy Developers' Guide to Features Want to use HSSF and XSSF read and write spreadsheets in a hurry? ...

  3. [Reprint]c++中typename和class的区别介绍

    在c++Template中,很多地方都用到了typename与class这两个关键字,而且好像可以替换,是不是这两个关键字完全一样呢?   相信学习C++的人对class这个关键字都非常明白,clas ...

  4. ruby初步学习中遇到的错误

    print <<off This is the second way of creating here document ie. multiple line string; off 报错: ...

  5. UVA 10891 Game of Sum(DP)

    This is a two player game. Initially there are n integer numbers in an array and players A and B get ...

  6. struts2的处理流程_2015.01.05

    01:首先经过web.xml里面的拦截 StrutsPrepareAndExecuteFilter 02:然后struts2内置的一些拦截器或用户自定义拦截器 Interceptor 03:用户编写的 ...

  7. logstash5.x改变

    5.x版本 logstash中 elasticsearch插件的workers,无法配置大于1,会提示 This plugin uses the shared and doesn't need thi ...

  8. Java高效编程之一【创建和销毁对象】

    一.考虑用静态工厂方法替代构造函数 代表实现:java.util.Collection Framework Boolean类的简单例子: public static Boolean valueOf ( ...

  9. html5的download下载标签

    Html5的下载标签download <a href="files/1.jpg" download="1.jpg">Download</a&g ...

  10. location.reload

    location.reload()-----重新加载缓存页面 location.reload(true)------重新加载服务器页面