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 ecjtulinlei at 2005-03-26 17:20:10 on Problem 1094
#include<stdio.h>
int relation[100][100],checksum,testsum,allcheck;
int findmore(int index1,int index2);
int findless(int index1,int index2)
{
  int i,k1,k2;
  if(index1>checksum||index2>checksum)return -1;
  if(index1==index2)return -1;
  if(relation[index1][index2]!=0)
  {
    if(relation[index1][index2]!=-1||relation[index2][index1]!=1)return -1;
    else return 1;
  }//if  
  relation[index1][index2]=-1;allcheck++;
  for(i=1;i<=checksum;i++)
  {
    if(relation[i][index1]==-1)
    {
      if(i==index2)return -1;
      k1=findless(i,index2);
      k2=findmore(index2,i);
      if(k1==-1||k2==-1)return -1;
    }//if  
  }//for i 
  return 1; 
}//findless
int findmore(int index1,int index2)
{
  int i,k1,k2;
  if(index1>checksum||index2>checksum)return -1;
  if(index1==index2)return -1;
  if(relation[index1][index2]!=0)
  {
    if(relation[index1][index2]!=1||relation[index2][index1]!=-1)return -1;
    else return 1;
  }  
  relation[index1][index2]=1;allcheck++;
  for(i=1;i<=checksum;i++)
  {
    if(relation[i][index1]==1)
    {
      if(i==index2)return -1;
      k1=findless(index2,i);
      k2=findmore(i,index2);
      if(k1==-1||k2==-1)return -1;
    }//if  
  }//for i  
  return 1;
}//findmore  
int main()
{
  int num[30],i,j,a,b,t,determine,position,k1,k2,kkk;char st[10];
  while(true)
  {
    scanf("%d%d",&checksum,&testsum);if(checksum==0&&testsum==0)break;
    determine=0;position=0;allcheck=0;kkk=checksum*(checksum-1);
    for(i=1;i<=checksum;i++)for(j=1;j<=checksum;j++)relation[i][j]=0;
    for(i=1;i<=testsum;i++)
    {
      scanf("%s",st);a=st[0]-'A'+1;b=st[2]-'A'+1;
      if(st[1]=='>')t=a,a=b,b=t;
      if(determine==1)continue;
      k1=findmore(b,a);k2=findless(a,b);
      if(k1==-1||k2==-1){determine=1,position=i;continue;}
      if(allcheck>=kkk&&!determine)determine=2,position=i;
    }//for i  
    if(determine==0)printf("Sorted sequence cannot be determined.\n");
    else if(determine==1)printf("Inconsistency found after %d relations.\n",position);
    if(determine!=2)continue;
    for(i=1;i<=checksum;i++)num[i]=i;
    for(i=1;i<=checksum;i++)
    {
      for(j=i+1;j<=checksum;j++)
      {
        if(relation[num[i]][num[j]]==1)
        {
          k1=num[i],num[i]=num[j],num[j]=k1;
        }//if    
      }//for j  
    }//for i  
    printf("Sorted sequence determined after %d relations: ",position);
    for(i=1;i<=checksum;i++)printf("%c",num[i]+'A'-1);
    printf(".\n");
  }//while  
}//main  

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