POJ 1013 小水题 暴力模拟

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.
",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.
",i+'A');
             }
             if(flag) break;
             a[i]=1;
        }
    }
    return 0;
}


原文地址:https://www.cnblogs.com/jiangu66/p/3188409.html