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

为什么是C提交CE,GCC提交RE呢,好郁闷!!!!

Posted by hongxingxiaonan at 2012-06-09 18:35:32 on Problem 1094
#include<stdio.h>
#include<string.h>
int g[27][27];
int relation[900][2];
int go[27];
int in[27];
int used[27];
int sorted;
int orderchar[27];
int m, n;
void find(int x){
	go[x]=1;
	int i;
	for(i=0; i<n; ++i)
		if(g[x][i]&&!go[i])
			find(i);
}
int topologic(int x){
	int i, next=x, hasnext=1;
	while(hasnext){
		x=next;
		orderchar[sorted]=x;
		int zeros=0;
		hasnext=0;
		for(i=0; i<n; ++i)
			if(g[x][i]) {			
				if((--in[i])==0) {next=i; ++zeros;}		
				++hasnext;
			}
		if(zeros>1) return 1;
		++sorted;				
	}
	if(sorted==n) return 0;
	return 1;
}
int main(){
	int l, r, i, j, k;
	while(scanf("%d%d", &n, &m)&&n){
		memset(g, 0, sizeof(g));
		memset(in, 0, sizeof(in));
		memset(relation, 0, sizeof(relation));
		memset(used, 0, sizeof(used));
		char s[5];
		int finish=0;
		for(i=0; i<m; ++i){
			scanf("%s", s);
			relation[i][0]=s[0]-'A';
			relation[i][1]=s[2]-'A';	
		}
		for(i=0; i<m; ++i){
			memset(go, 0, sizeof(go));		
			l=relation[i][0]; r=relation[i][1];
			g[l][r]=1; used[l]=1; used[r]=1;
			find(r);
			if(go[l]){				
				printf("Inconsistency found after %d relations.\n", i+1);
				finish=1;
				break;
			}
			++in[r];
			sorted=0;
			int zeros=0, enternum=0, location;
			for(j=0; j<n; ++j) enternum+=used[j];
			if(enternum<n) continue;
			for(j=0; j<n; ++j)if(in[j]==0&&used[j]){location=j;  ++zeros;}
			if(zeros>1) continue;			
			int flag=topologic(location);
			if(flag==0){				
				printf("Sorted sequence determined after %d relations: ", i+1);
				for(j=0; j<n; ++j)
					printf("%c", ((char)orderchar[j]+65));
				printf(".\n");
				finish=1;
				break;
			}
			if(flag==1){				
				for(j=0; j<n; ++j)
					for(k=0; k<n; ++k)
						if(g[j][k]) ++in[k];				
				continue;	
			}			
		}
		if(!finish) 
			printf("Sorted sequence cannot be determined.\n");		
	}
	return 0;
}

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