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

WHY RE,求数据

Posted by 306469974 at 2013-09-09 21:25:09 on Problem 1833
#include <iostream>
#include <stdio.h>
#include <memory.h>
#include <algorithm>
#include <string.h>
#include <stack>
using namespace std;
const int M=2000;
int st[M];
bool f[M];
int main()
{
	int m,n,k,i,top,cnt,cur;
	scanf("%d",&m);
	while (m--)
	{
		scanf("%d%d",&n,&k);
		top=n;
		for (i=0;i<n;++i)
			scanf("%d",&st[i]);
		cnt=-1;
		memset(f,true,n+1);
		while (true)
		{
			if (top==n)
			{
				if(++cnt==k)
					break;
				cur=st[--top];
				f[cur]=false;
			}
			for (++cur;cur<=n;++cur)
				if (!f[cur])
					break;
			if (cur<=n)
			{
				st[top++]=cur;
				f[cur]=true;
				cur=0;
			}
			else
			{
				cur=st[--top];
				f[cur]=false;
				if (top==0&&cur==n)
					cur=0;
			}
		}
		for (i=0;i<n-1;++i)
			printf("%d ",st[i]);
		printf("%d\n",st[i]);
	}
	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