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

本人用递归做,没有涉及排序,测试用例通过了但是提交后wa,大家帮忙看看出了什么问题呢

Posted by denganliang at 2011-03-30 18:35:09 on Problem 2367
#include <stdio.h>
int flag[101][101],a[101],n;
void swap(int *te,int *tb){
	int temp;
	temp=*te;
	*te=*tb;
	*tb=temp;
	}
int test(int c,int list[101],int j){
	int i,k,f;
	for(i=1;i<=n;i++){
		if(flag[c][i]==1) { 
			f=0;
		for(k=0;k<j;k++){
		if(i==list[k]) f=1;
		  }
		  if(f==0) return 0;
		  }
		}
	  return 1;
	}

void find(int key,int list[100],int j){
 	 int i;
 	 if(key==n) {
		 list[n-1]=a[n];
		 for(i=0;i<n;i++){
		  printf("%d",list[i]);
		  if(i!=n-1) printf(" ");
		  }
		  printf("\n");
		 }
     else {
		  for(i=key;i<=n;i++)
		   {
			 if(test(a[i],list,j)==1) {
				 swap(&a[i],&a[key]);
				 list[j]=a[key];
				 find(key+1,list,j+1); 
				 swap(&a[i],&a[key]);
				 }
			 }
		 
		 }
	}

int main(){
	int i,j,temp,list[100];
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		list[i-1]=0;
		a[i]=i;
		for(j=1;j<=n;j++)
		  flag[i][j]=0;
		}
	for(i=1;i<=n;i++){
		while(1){
			getchar();
			temp=getchar()-'0';
			if(temp==0) break;
			flag[temp][i]=1;
			}
		}
	find(1,list,0);
	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