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

代码写得又屎又长 ,求大牛给简短代码以供膜拜

Posted by Sayakiss at 2010-07-15 20:44:24 on Problem 1094
= =我太挫了 
#include<cstdio>
#include<cstdlib>
#include<cstring>
int p[30],tp[30],g[30][30],n,m,i,j,sol,mt,saya;
char s[30];
int ts()
{
    int f[30]={0},fir=1,nd=n,findi=0,nfind=0;
	char ss[30];
	memset(ss,0,sizeof(ss));
    while (1)
    {
          fir=1;findi=0;		  
          for (i=1;i<=n;i++)
          {
			  if (tp[i]==0&&!f[i]) 
				  if (fir)
				  {
					  f[i]=1;
					  fir=0;
					  findi=i;
					  ss[strlen(ss)]='A'+i-1;
					  nd--;
				  }
				  else {nfind=1;break;}
          }
          if (!nd) 
          {
			       if (nfind) return 0;
                   printf("Sorted sequence determined after %d relations: %s.",mt,ss);
                   memset(ss,0,sizeof(ss));
                   return 1;
          }
          if (findi) for(i=1;i<=n;i++) if (g[findi][i]) tp[i]-=g[findi][i];
          if (!findi) return -1;
    }
}
        
int main()
{
	while (scanf("%d%d",&n,&m),n&&m)
    {
          sol=0;mt=1;memset(g,0,sizeof(g));memset(p,0,sizeof(p));
          while (mt<=m)
          {
              memset(s,0,sizeof(s));  
			  scanf("%s",s);getchar();
			  if (!sol)
              {
              p[s[2]-'A'+1]++;
              g[s[0]-'A'+1][s[2]-'A'+1]++;
              memcpy(tp,p,sizeof(p));
              saya=ts();
              if (saya==1) {sol=1;printf("\n");}
              if (saya==-1) {sol=1;printf("Inconsistency found after %d relations.\n",mt);}
              if (saya==0&&mt==m) {sol=1;printf("Sorted sequence cannot be determined.\n");}
              }
			  mt++;
          }
    }
}

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