Counterfeit Dollar
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 35774   Accepted: 11390

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. 

Source

East Central North America 1998

题意 :

 有12个硬币 有一个是假的 比其他的或轻或重     分别标记为A到L

然后输入cas 有个cas组数据

每组输入3行 每行3个字符串 第一个表示当时天平上左边有哪几个字符  第二个是右边 2边个数一样 但是不一定有几个    之后第三个字符串描述左边是比右边大小还是相等

问你  哪一个硬币是假的  假的相对于真的是清还是重        

保证有解

思路:暴力模拟 暴力哪一个是假的  总共只有12个  很好暴力

#include<stdio.h>
#include<string.h>
int a[100];
char s[3][3][20];
int solve()
{
int i,j,k,len,n1,n2;
for(k=0;k<3;k++)
{
n1=0;n2=0;
len=strlen(s[k][0]);
for(i=0;i<len;i++)
n1+=a[s[k][0][i]-'A'];
for(i=0;i<len;i++)
n2+=a[s[k][1][i]-'A'];
if(strcmp(s[k][2],"even")==0)
if(n1!=n2) break;
if(strcmp(s[k][2],"up")==0)
if(n1<=n2) break;
if(strcmp(s[k][2],"down")==0)
if(n1>=n2) break;
}
if(k==3) return 1;
return 0;
}
int main()
{
int cas,i,j,flag;
scanf("%d",&cas);
while(cas--)
{
flag=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%s",s[i][j]);
for(i=0;i<12;i++) a[i]=2;
for(i=0;i<12;i++)
{
a[i]=1;
if(solve())
{
flag=1;
printf("%c is the counterfeit coin and it is light.\n",i+'A');
}
if(flag) break;
a[i]=2;
}
if(flag) continue;
for(i=0;i<12;i++) a[i]=1;
for(i=0;i<12;i++)
{
a[i]=2;
if(solve())
{
flag=1;
printf("%c is the counterfeit coin and it is heavy.\n",i+'A');
}
if(flag) break;
a[i]=1;
}
}
return 0;
}

POJ 1013 小水题 暴力模拟的更多相关文章

  1. poj 1005:I Think I Need a Houseboat(水题,模拟)

    I Think I Need a Houseboat Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 85149   Acce ...

  2. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  3. hdu 2117:Just a Numble(水题,模拟除法运算)

    Just a Numble Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  4. hdu5007 小水题

    题意:       给你一个串,如果出现子串 "Apple", "iPhone", "iPod", "iPad"输出MA ...

  5. poj 3264 RMQ 水题

    题意:找到一段数字里最大值和最小值的差 水题 #include<cstdio> #include<iostream> #include<algorithm> #in ...

  6. Poj 1552 Doubles(水题)

    一.Description As part of an arithmetic competency program, your students will be given randomly gene ...

  7. hdu 4540 威威猫系列故事——打地鼠 dp小水题

    威威猫系列故事——打地鼠 Time Limit: 300/100 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total ...

  8. Crashing Robots(水题,模拟)

    1020: Crashing Robots 时间限制(普通/Java):1000MS/10000MS     内存限制:65536KByte 总提交: 207            测试通过:101 ...

  9. POJ 1837 Balance 水题, DP 难度:0

    题目 http://poj.org/problem?id=1837 题意 单组数据,有一根杠杆,有R个钩子,其位置hi为整数且属于[-15,15],有C个重物,其质量wi为整数且属于[1,25],重物 ...

随机推荐

  1. Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException

    1.错误描写叙述 信息: Initializing c3p0-0.9.2.1 [built 20-March-2013 10:47:27 +0000; debug? true; trace: 10] ...

  2. Serialization performance analysis

    Serialization performance analysis http://www.skyscanner.net/blogs/serialization-performance-analysi ...

  3. 日积月累系列之省市选择器(js源码)

    省市选择器是大家经常用到的, 但网上找的省市选择器都不是很实用,于是自己写了移动端的省市选择器. 界面: 源码结构: 演示地址:http://component.cform.cn/city/ 演示二维 ...

  4. 模板专业化和模板偏特样片(template specialization and partial template specialization)

    测试环境: win7 64 g++ 4.8.1 /*************************************************************************** ...

  5. 【剑指offer】员工年龄排序

    典型的以空间换时间问题,思路非常重要! /* 员工年龄排序 员工可能有几万名,要求时间复杂度为O(n) 思路:员工的年龄必定在一个范围内,比方0-99,那么我们建立一个大小为100的辅助数组,然后遍历 ...

  6. 输入 URL 到页面完成加载过程中的所有发生的事情?

    转到浏览器中输入URL给你一个页面后,.有些事情,你每天都在使用,学的是计算机网络知道是怎么回事.DNS解析然后页面的回馈,只是要讲好还是有难度. 之前fex团队的nwind专门写过这个问题的博客: ...

  7. at System.Data.EntityClient.EntityConnection.GetFactory(String providerString)

    最近在做一个WinForm的项目. 使用vs2013开发. 数据库使用的是oracle. 在本地写了一个webservice .测试正常.发布到服务器的时候.就是提示了错误. 打开服务器上的日志.看到 ...

  8. 31、Thinking in Java

  9. unbuntu下的root 用户和 sudo 命令

    参考: http://james23dier.iteye.com/blog/721246 http://blog.csdn.net/shichexixi/article/details/5969993 ...

  10. 【转】Android学习之AndroidManifest.xml清单之<uses-feature>

    无意之中看了几个小时的官方英文文档,关于<uses-feature>的介绍.有必要在这里记录一下,应该有很多人不知道<uses-feature>到底是做什么用的,因为我们平时根 ...