POJ 1013 Counterfeit Dollar
来源:互联网 发布:亿阳信通程序员怎么样 编辑:程序博客网 时间:2024/06/18 12:53
Counterfeit Dollar
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 39972 Accepted: 12734
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.
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个钱币,其中有一个是假的,所有的真币的质量都相同,唯一的假币可能的质量可能比真币重,可能比真币轻,最后要求哪个钱币是假的,而且说出假的那个钱币是比真币重还是比真币轻;
#include<iostream>#include<string.h>#include<stdlib.h>#include<stdio.h>#include<algorithm>#include<string>#include<cmath>using namespace std;int main(){ int T; cin >> T; while(T--) { char le[130][130],ri[130][130]; string p[100]; int b[130]; int aa[130]; memset(b,0,sizeof(b)); memset(aa,0,sizeof(aa)); for(int i=0; i<3; i++) { cin >> le[i] >> ri[i] >> p[i]; } for(int j=0; j<3; j++) { if(p[j] == "even") { for(int i=0; le[j][i]!='\0'; i++) { aa[le[j][i]-'A'] = 1; aa[ri[j][i]-'A'] = 1; } } else if(p[j] == "up") { for(int i=0; le[j][i]!='\0'; i++) { b[le[j][i]-'A']++; b[ri[j][i]-'A']--; } } else if(p[j] == "down") { for(int i=0; le[j][i]!='\0'; i++) { b[le[j][i]-'A']--; b[ri[j][i]-'A']++; } } } int max = 0; int flag = 0; int i; int ff = 1; for(i=0; i<12; i++) { if(aa[i] == 0) { if(b[i]<0 && fabs(b[i])>max) { max = fabs(b[i]); ff = i; flag = 1; } else if(b[i]>0 && fabs(b[i])>max) { max = fabs(b[i]); ff = i; flag = 0; } } } if(flag == 1) { printf("%c is the counterfeit coin and it is light.\n",ff+'A'); } else { printf("%c is the counterfeit coin and it is heavy.\n",ff+'A'); } } return 0;}
0 0
- POJ 1013 Counterfeit Dollar
- POJ 1013 Counterfeit Dollar
- POJ 1013 Counterfeit Dollar
- POJ 1013 Counterfeit Dollar
- POJ 1013 Counterfeit Dollar
- POJ 1013 Counterfeit Dollar
- POJ 1013 Counterfeit Dollar
- POJ 1013 Counterfeit Dollar
- POJ 1013 counterfeit dollar
- POJ 1013 Counterfeit Dollar
- poj 1013 Counterfeit Dollar
- POJ 1013 Counterfeit Dollar
- poj 1013 Counterfeit Dollar
- poj-1013 Counterfeit Dollar
- POJ 1013 Counterfeit Dollar
- POJ-1013-Counterfeit Dollar
- poj 1013 Counterfeit Dollar
- [POJ][1013]Counterfeit Dollar
- 设计类图书
- 2029 Palindromes _easy version
- soa---java 多线程-线程内存模型
- CentOS搭建LNMP
- 黑马程序员_Java基础篇(五)——反射
- POJ 1013 Counterfeit Dollar
- MySQL学习笔记1
- ExpandableListView实现二层和三层列表源码
- 调试经验--硬盘与U盘
- NodeJS、NPM安装配置步骤(windows版本)
- Python小玩具:BMP转字符画(多线程?)
- 静默建库
- 堆内存和栈内存详解
- Source Insight函数调用关系显示设置