标签:
题目大意:
分析:
AC code:
#include <cstdio>
#include <algorithm>
#define mp make_pair
#define pii pair<int,int>
#define x first
#define y second
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
const int MAXN = 1009;
int n;
short a[MAXN];
short ans[MAXN<<1];
short vis[MAXN];
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%d", a+i);
for(int i = (n<<1); i >= 1; --i)
{
int c1 = -1, c2 = -1;
for(int j = 1; j <= n; ++j)
if(!a[j] && !vis[j])
{
c1 = j;
break;
}
if(c1 != -1)
{
ans[i] = c1;
vis[c1] = 1;
for(int j = 1; j <= n; ++j)
if(!vis[j] && j < c1)
--a[j];
}
else
{
for(int j = n*2; j > i; --j)
if(ans[j] > 0 && vis[ans[j]] == 1)
{
c2 = ans[j];
break;
}
if(c2 == -1)
{
puts("NO");
return 0;
}
ans[i] = -c2;
vis[c2] = 2;
for(int j = 1; j <= n; ++j)
if(!vis[j] && j > c2)
--a[j];
}
}
puts("YES");
for(int i = 1; i <= (n<<1); ++i)
printf("%d ", ans[i]);
puts("");
#ifndef ONILNE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
return 0;
}
标签:
原文地址:http://blog.csdn.net/qq_20118433/article/details/46627751