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:各位大虾看一下我的程序错在哪里?thx!

Posted by Coldwings at 2005-04-20 16:24:53 on Problem 1833
In Reply To:各位大虾看一下我的程序错在哪里?thx! Posted by:project at 2004-09-24 16:28:15
模拟也能AC的话这道题就真是恶心了

> 检查了很久都发现不了哪里有错,麻烦帮忙看一下:
> Codes:
> #include<stdio.h>      
> #include<string.h>
> void dao(int a[],int n)//数组倒序
> {
> 	int i,k;
> 	for(i=0;i<n/2;i++){
> 		k=a[n-i-1];a[n-i-1]=a[i];a[i]=k;
> 	}
> }
> int main()
> {
> 	int i,j,k,l,m,n,total,n1,k1,x;int ch,min;int str[1024];
> 	while(scanf("%d",&m)!=EOF){
> 		for(x=0;x<m;x++){
> 		scanf("%d%d",&n1,&k1);
> 		total=0;
> 		for(i=0;i<n1;i++)
> 			scanf("%d",&str[i]);
> 		if(n1==1){printf("%d\n",str[0]);continue;}
> 		do{
> 			k=0;
> 			if(total==k1){
> 				printf("%d",str[0]);
> 				for(j=1;j<n1;j++)
> 					printf(" %d",str[j]);
> 				printf("\n");k=0;break;
> 			}
> 			for(i=n1-2;i>=0;i--){//一个个的往后找下一个组合
> 				k=0;min=100000000;
> 				for(j=i+1;j<n1;j++){
> 					if(str[j]>str[i])
> 						if(min>str[j]){
> 							min=str[j];
> 							l=j;k=1;
> 						}
> 				}
> 				if(!k) continue;
> 				ch=str[i];str[i]=str[l];str[l]=ch;
> 				for(j=i+1;j<n1-1;j++){                  //排序
> 					for(n=j+1;n<n1;n++){
> 						if(str[j]>str[n]) {
> 							ch=str[j];str[j]=str[n];str[n]=ch;
> 						}
> 					}
> 				}
> 			    total++;
> 				if(total==k1){          
> 					printf("%d",str[0]);
> 					for(j=1;j<n1;j++)
> 						printf(" %d",str[j]);
> 					printf("\n");k=0;break;
> 				}								
> 			}
> 			if(!k&&total<k1){dao(str,n1);total++;}//已经找到了最后一个之后再循环
> 			else if(total==k1) break;
> 		}while(1);
> 		}
> 	}
> 	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