Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

没什么好怀疑的,就是用wrong123的那个思路 。

Posted by Sayakiss at 2010-06-17 16:15:14 on Problem 1013 and last updated at 2010-06-17 21:36:56
因为只有一枚假币,凡是不平衡出现都必然有这个家伙,那么他的怀疑值必然为最大,或者最大之一,题目说了保证有解,那么有且仅有一个没有标记为真且怀疑值为最大的硬币就是那个解。

代码

# include <stdio.h>
# include <string.h>

char s1[20],s2[20],r[20];
int f[20],fn[20],i,j,n;
int main()
{
    scanf("%d",&n);
    while (n>0,n--)
    {
          memset(f,0,sizeof(f));
          memset(fn,0,sizeof(fn));
          for (i=0;i<3;i++)
          {
              memset(s1,0,sizeof(s1));
              memset(s2,0,sizeof(s2));
              memset(r,0,sizeof(r));
              scanf("%s%s%s",s1,s2,r);
              if (r[0]=='e') for (j=0;j<strlen(s1);j++) {f[s1[j]-'A']=1;f[s2[j]-'A']=1;}
              if (r[0]=='u') for (j=0;j<strlen(s1);j++) {fn[s1[j]-'A']++;fn[s2[j]-'A']--;}
              if (r[0]=='d') for (j=0;j<strlen(s1);j++) {fn[s1[j]-'A']--;fn[s2[j]-'A']++;}
          }
          int max=-1,ans;
          for (i=0;i<12;i++) if ((abs(fn[i])>max)&&(!f[i])) {max=abs(fn[i]);ans=i;}
          printf("%c is the counterfeit coin and it is ",ans+'A');
          if (fn[ans]<0) printf("light.\n");
           else printf("heavy.\n");
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator