poj1013,POJ1013-Counterfeit Dollar

一、题目:Counterfeit Dollar
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 30366 Accepted: 9520
Description
Sally Jones has a dozen Voyageur silver dollars. However, _disibledevent=>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, _disibledevent=>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
二、思路
1:(模拟)
由于该题必然有确定的判定,所以简单的可以这么想: 设置两个数组: real[12]-标志为真 lh[12]--标志被怀疑 每次称球的时候,如果是"even"则把对应的设置为"真东西",即置为1, 如果是"up"或"donw" 则把表示轻重的数组lh对应的 ++ 或者 --,直到最后。 然后把所有对应real中为1(即就是真东西啦)的lh置为0;那么操作之后, lh中存在没有辨认出真的,就是一系列的例如: -1,-2,1,2,3等数值,那么 假东西就是其中绝对值最大的那个!!------被怀疑次数最多,所以它为假。
2:(搜索)
枚举哪一枚硬币是假币,并且是轻还是重,代入三个不等式中检测即可。。。。
三、测试数据
2 ABCD EFGH even ABCI EFJK up ABIJ EFGH even
A B up A C up D E even
结果:
K is the counterfeit coin and it is light. A is the counterfeit coin and it is heavy.
四、ac源代码
#include #include int abs(int a) { if(a<0) return -a; else return a; } int main() { int i,j,max=0,mark,s,k; int real[500]; char input[3][2][30]; char balance[3][10]; freopen("g:\\a.in","r",stdin); scanf("%d",&s); for(k=0;k(int)abs(max)) { max=real[i]; mark=i; } if(max>0) printf("%c is the counterfeit coin and it is heavy.\n",mark); else printf("%c is the counterfeit coin and it is light.\n",mark); } return 0; }
Tags: 

延伸阅读

最新评论

发表评论