Codeforces Round #604(Div. 2,

// https://codeforces.com/contest/1265/problem/D
/*
感觉像是遍历的思维构造题 有思路就很好做的
可以把该题想象成过山车或者山峰......
*/
#include<iostream>
#include<cstdio>
using namespace std;

int n;
int cnt[5], last[5]; // last 是记录当前还有多少 0, 1, 2, 3
int ans[100005];
bool ok;

int main()
{
for(int i = 0; i < 4; i++) {
scanf("%d", &cnt[i]);
n += cnt[i]; // n 就是输出的总长度
}

for(int i = 0; i < 4; i++){
if(!cnt[i]) continue;
ans[1] = i; // 依次取 0, 1, 2, 3 为第一位开始
ok = true;
for(int j = 0; j < 4; j++){
last[j] = cnt[j] - (i == j); // 初始化 last
}

for(int j = 2; j <= n; j++){ // 因为第一位已经放了所以从第二位开始
int p = ans[j - 1];
if(p - 1 >= 0 && last[p - 1]){ // 往小(低)处走
ans[j] = p - 1; last[p - 1]--;
}
else if(p + 1 < 4 && last[p + 1]){ // 往大(高)处走
ans[j] = p + 1; last[p + 1]--;
}
else ok = false; // 假如都不能 则当前做法不可取
}
if(ok){
printf("YES\n");
for(int i = 1; i <= n; i++){
printf("%d%c", ans[i], i == n ? '\n' : ' ');
}
break;
}
}
if(!ok) printf("NO\n");

return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/hgangang/p/12003153.html