###### poj1013 Counterfeit Dollar

http://poj.org/problem?id=1013

12个硬币里有1个假币，枚举每一个硬币，如果它是轻或是重，则为假币。

假设它就是轻。然后由天平三次称量结果倒推：如果称量结果为up，则它一定在右边。如果称量结果为even，则它既不在左边，也不在右边。如果称量结果为down，则它一定在左边。上述都满足，则毫无疑问它就是轻。否则有一个不成立，它就不为轻。

#include <stdio.h>
#include <string.h>
char left[3][7],right[3][7],result[3][5];
int inLeft(int i,char x)
{
int j;
for(j=0;j<strlen(left[i]);j++)
if(left[i][j]==x)
return 1;
return 0;
}
int inRight(int i,char x)
{
int j;
for(j=0;j<strlen(right[i]);j++)
if(right[i][j]==x)
return 1;
return 0;
}
int isLight(char x)//判断硬币x是否为轻
{
int i;
for(i=0;i<3;i++)
{
switch(result[i][0])
{
case 'u':if(!inRight(i,x)) return 0;
break;
case 'e':if(inLeft(i,x)||inRight(i,x)) return 0;
break;
case 'd':if(!inLeft(i,x)) return 0;
break;
}
}
return 1;
}
int isHeavy(char x)//判断硬币x是否为重
{
int i;
for(i=0;i<3;i++)
{
switch(result[i][0])
{
case 'u':if(!inLeft(i,x)) return 0;
break;
case 'e':if(inLeft(i,x)||inRight(i,x)) return 0;
break;
case 'd':if(!inRight(i,x)) return 0;
break;
}
}
return 1;
}
int main()
{
char ch;
int n;
scanf("%d",&n);
while(n--)
{
scanf("%s %s %s",left[0],right[0],result[0]);
scanf("%s %s %s",left[1],right[1],result[1]);
scanf("%s %s %s",left[2],right[2],result[2]);
for(ch='A';ch<='L';ch++)//枚举12个硬币
{
if(isLight(ch))
{
printf("%c is the counterfeit coin and it is light.\n",ch);
break;
}
else if(isHeavy(ch))
{
printf("%c is the counterfeit coin and it is heavy.\n",ch);
break;
}
}
}
return 0;
}



#### POJ 1013 Counterfeit Dollar 找假硬币 模拟

2017-08-07 10:17:17

#### POJ1013-Counterfeit Dollar

2011-08-04 22:56:41

#### Counterfeit Dollar - POJ 1003 水题

2014-07-02 10:26:07

#### POJ-1013 Counterfeit Dollar

2015-02-13 21:49:47

#### FZU 1003 Counterfeit Dollar

2015-08-09 15:16:49

#### POJ 1013：Counterfeit Dollar

2015-07-30 09:32:09

#### FOJ Problem 1003 Counterfeit Dollar

2016-09-04 22:27:56

#### Counterfeit Dollar(POJ1013

2015-07-28 14:57:48

#### POJ1013——Counterfeit Dollar

2017-02-28 21:45:55

#### POJ1013 Counterfeit Dollar(技巧)

2016-01-25 20:48:52

## 不良信息举报

poj1013 Counterfeit Dollar