码迷,mamicode.com
首页 > 其他好文 > 详细

Counterfeit Dollar

时间:2015-04-01 22:00:14      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:模拟   暴力   

题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=16424

题意 :
 有12个硬币 有一个是假的 比其他的或轻或重     分别标记为A到L
然后输入cas 有个cas组数据
每组输入3行 每行3个字符串 第一个表示当时天平上左边有哪几个字符  第二个是右边 2边个数一样 但是不一定有几个    

之后第三个字符串描述左边是比右边大小还是相等
问你  哪一个硬币是假的  假的相对于真的是清还是重  (假硬币有轻有重,只有一枚是假硬币)       
保证有解

"up":右轻 
<pre name="code" class="plain">"down":右重 
"even":一样重






#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int v[15],cot[15];
int fun(int x)
{
  if(x<0) return -x;
   return x;    
}
int main()
{
  int i,j,t;
  char a[15],b[15],c[5];  
   scanf("%d",&t);
     while(t--)
     {
         memset(v,0,sizeof(v));
         memset(cot,0,sizeof(cot));
        for(i=0;i<3;i++)
         {
           scanf("%s%s%s",a,b,c);               
          if(strcmp(c,"up")==0)
           {//右轻 
              for(j=0;j<strlen(a);j++)
               {
                 cot[a[j]-'A']++;
                 cot[b[j]-'A']--;                       
               }                                    
           }             
           else if(strcmp(c,"down")==0)
           {//右重 
             for(j=0;j<strlen(a);j++)
              {
                cot[a[j]-'A']--;
                cot[b[j]-'A']++;                       
              }     
           } 
           else 
            {
              for(j=0;j<strlen(a);j++)
               {
                 v[a[j]-'A']=1;
                 v[b[j]-'A']=1;                       
               }    
            }             
        }  
        int m=-1,ans,f;
      for(i=0;i<12;i++)
       {
         if(!v[i])
          {
            if(m<fun(cot[i]))
             {
               m=fun(cot[i]);
                ans=i;
                f=cot[i];                  
             }          
          }                
       } 
       if(f>0) printf("%c is the counterfeit coin and it is heavy.\n",ans+'A');
         else printf("%c is the counterfeit coin and it is light.\n",ans+'A');              
     }                            
   
    return 0;
}


Counterfeit Dollar

标签:模拟   暴力   

原文地址:http://blog.csdn.net/u012346225/article/details/44812627

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!