| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
WHY RE,求数据#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator