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

大家快来看看! 这个题不就是UVA的120吗 怎么我在这里就是过不了呢? 大家帮帮我啊!

Posted by elf788544 at 2005-12-19 22:21:22 on Problem 2275
我的方法是 先从大到小排序b数组,依次看每一次当前最大的是不是在最终的位置上,若不在先把他放在最上面,然后再把他放到最终位置上,   这样一定能得到最终的结果,但是 WA个不停啊!!
大家帮帮我啊!
这是我的code:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[50],b[50],n;
bool big(int x,int y)
{
	return x>y;
}

int main()
{
	int i,j;
	while(scanf("%d",&n)&&n)
	{		
		for(i=1;i<=n;i++)
			scanf("%d",&a[i]);
		reverse(&a[1],&a[n+1]);
		
		int tmp[50]={0},tp=1;
		for(i=1;i<=n;i++)
			b[i]=a[i];
		sort(b+1,b+n+1,big);
		
		for(i=1;i<=n;i++)
		{
			for(j=n;j>=i;j--)
			{
				if(b[i]==a[j])
				{
					if(i==j)
						;
					else
					{
						if(j!=n)
						{
							tmp[tp++]=n-j+1;
							tmp[tp++]=n-i+1;
					    	reverse(&a[j],&a[n+1]);
						
					    	reverse(&a[i],&a[n+1]);
						}
						else
						{
							tmp[tp++]=n-i+1;
							reverse(&a[i],&a[n+1]);
						}				
					}
					break;
				}
			}
		}
		printf("%d",tp-1);
		for(i=1;i<tp;i++)
			printf(" %d",tmp[i]);
		printf("\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