codeforces 1264 B 贪心xg
题意:给了4个数0,1,2,3。的数量a,b,c,d。要组成一个排列abs(ai+1-ai)等于1。组成不了则输出no,否则输出任意排列顺序。
思路:ifelse暴力肯定是能做的。最先是想查询从出现最多次数的数字贪心,如果前面一个数的数量不等于0,则游动下标pos--,否则pos++;后来发现这样有些样例过不了。
因为就4个数字,索性直接四个数字全都当首字母暴力搞一搞,然后判断队列中有多少个字符瞎搞即可。
#include <iostream> #include <cmath> #include <cstdio> #include <cstring> #include <string> #include <map> #include <iomanip> #include <algorithm> #include <queue> #include <stack> #include <set> #include <vector> // #include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define sp ' ' #define endl '\n' #define inf 0x3f3f3f3f; #define FOR(i,a,b) for( int i = a;i <= b;++i) #define bug cout<<"--------------"<<endl #define P pair<int, int> #define fi first #define se second #define pb(x) push_back(x) #define ppb() pop_back() #define mp(a,b) make_pair(a,b) #define ms(v,x) memset(v,x,sizeof(v)) #define rep(i,a,b) for(int i=a;i<=b;i++) #define repd(i,a,b) for(int i=a;i>=b;i--) #define sca3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c)) #define sca2(a,b) scanf("%d %d",&(a),&(b)) #define sca(a) scanf("%d",&(a)); #define sca3ll(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c)) #define sca2ll(a,b) scanf("%lld %lld",&(a),&(b)) #define scall(a) scanf("%lld",&(a)); using namespace std; typedef long long ll; ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;} ll powmod(ll a, ll b, ll mod){ll sum = 1;while (b) {if (b & 1) {sum = (sum * a) % mod;b--;}b /= 2;a = a * a % mod;}return sum;} const double Pi = acos(-1.0); const double epsilon = Pi/180.0; const int maxn = 2e5+10; //int a[5]; map<int,int>a; int b[maxn]; void hhh() { rep(i,0,3){ a[i] = b[i]; //sum += a[i]; } } int main() { //freopen("input.txt", "r", stdin); //ll a,b,c,d; int sum = 0; rep(i,-1,4){ a[i] = 0; } rep(i,0,3){ cin>>a[i]; b[i] = a[i]; sum += a[i]; } queue<int>que; int flag = 0; rep(i,0,3){ hhh(); if(a[i] == 0) continue; int pos = i; string s = "0123"; //que.clear(); while(que.size()){ que.pop(); } while(1){ a[pos]--; que.push(s[pos]); if(a[pos-1]){ pos--; } else if(a[pos+1]){ pos++; } else { break; } } if(que.size() == sum) { flag = 1; break; } } if(flag == 0){ cout<<"NO"<<endl; } else { cout<<"YES"<<endl; while(que.size()){ char tmp = que.front(); que.pop(); cout<<tmp<<sp; } } }