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 407811696 at 2011-04-13 07:27:19 on Problem 2085
In Reply To:还以为用next_permutation,邪恶了 Posted by:407811696 at 2011-04-12 21:43:24
#include <iostream>
#include <cstdio>
using namespace std;
int a[50005];
int n,m;
int main()
{
//	freopen("1.txt","r",stdin);
	while(scanf("%d%d",&n,&m),!(n==-1&&m==-1))
	{		
		int i,j,k,p;
		for(i=1;i<=n;i++)
			a[i]=i;
		if(m!=0)
		{
			for(i=0;m;)
			{
				if(m>i+1)
				{
					i++;
					m-=i;
				}
				else
				{
					i++;
					break;
				}
			}
			k=n-i+m;
			for(j=n-i,p=n;j<=n;j++)
			{
				if(k!=j)
					a[p--]=j;
			}
			a[p]=k;
		}
		for(i=1;i<=n;i++)
		{
			if(i!=1)
				printf(" ");
			printf("%d",a[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