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

Re:不知道错哪了

Posted by aygxylxk at 2010-03-30 20:16:21 on Problem 1033
In Reply To:不知道错哪了 Posted by:aygxylxk at 2010-03-30 20:15:29
#include<iostream>
using namespace std;
int main(){
	int a[10001],b[10001];
	memset(a,0,10001);
	memset(b,0,10001);
	int cluster=0,file=0,num=0;
	int t=0,j=0,i=0,sign=0;
	
	scanf("%d%d",&cluster,&file);
	for(i=1;i<=file;i++){
		scanf("%d",&num);
		t+=num;
		for(j=t-num+1;j<=t;j++){
			scanf("%d",&a[j]);
			b[a[j]]=a[j];
		}
	}//for
	for(i=1;i<j;i++){
		if(b[i]==0){
			printf("%d %d\n",a[i],i);
			b[i]=a[i];
			b[a[i]]=0;
			a[i]=0;
		}
		else
			if(b[i]==a[i]){
				a[i]=0;
			}
	}
	for(i=1;i<j;i++){
		if(a[i]!=0){
			sign=1;
			if(b[i]==0){
				printf("%d %d\n",a[i],i);
				b[i]=b[a[i]];
			    b[a[i]]=0;
			    a[i]=0;
			}//if
			else{
				while(b[cluster]!=0)
					cluster--;
				printf("%d %d\n",b[i],cluster);
				b[cluster]=b[i];
				printf("%d %d\n",a[i],i);
				b[i]=a[i];
				a[a[i]]=cluster;
				b[a[i]]=0;
				a[i]=0;
			}//else
		}//if
	}//for
	if(sign==0){
		printf("No optimization needed\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