码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #604(Div. 2,

时间:2019-12-07 21:39:32      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:tps   不能   多少   codeforce   http   can   ios   scanf   iostream   

// 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;
}

  

Codeforces Round #604(Div. 2,

标签:tps   不能   多少   codeforce   http   can   ios   scanf   iostream   

原文地址:https://www.cnblogs.com/hgangang/p/12003153.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!