Codeforces Round #105 补题报告

C-Terse Princess

题目大意:构造出一个数组,长度为n,满足,比前面所有数字的和都要大的恰好为b个,比前面所有数都大(并且不比前面的数字和都大)的恰好为a个,第一个数不算。

思路:可以先构造出比前面所有数都大的数b个(1, 2, 4 ... 2^n), 最后一个数设置的比较大(比如50000 - 100),然后再构造出a个比前面大的(49001,49002...),若此时超出n个数那显然就找不到合适的了;若不是,则后面的数为48999,48998。。。

当b=0时,直接设置一个比较大的数,后面就同上

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
#define pf printf
#define pq priority_queue
#define sc(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define rep(i, s, e) for(int i = s;i <= e; ++ i)

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
int n, a, b;
int f[110];
bool vis[500005];
vector<int> ans;
int main()
{
    for(int i = 1;i <= 20; ++ i) {
        f[i] = 1 << (i-1);
    }
    cin >> n >> a >> b;
    for(int i = 1;i <= b; ++ i) {
        vis[f[i]] = true;
        ans.push_back(f[i]);
    }
    int c = 48000, cnt = 0, x = 1;
//    int k = c - a - 10;
    int t = c - 1;
    if(ans.size() == 0 && a) {
        ans.push_back(++c);
        ans.push_back(233);
    }
    ans.push_back(++c);
    if(b == 0) cnt ++;
    while(cnt < a) {
        ans.push_back(++ c);
        cnt ++;
    }
    while(ans.size() < n) {
        if(!vis[t])
        ans.push_back(t --);
        else {
            puts("-1");
            return 0;
        }
    }
//    cout << ans.size() << endl;
//    for(int i = 0;i < ans.size(); ++ i) cout << ans[i] << " ";
//    puts("");
    if(ans.size() != n) {
        puts("-1");
        return 0;
    }
    for(int i = 0;i < ans.size(); ++ i) {
        cout << ans[i] << " ";
    } puts("");
    return 0;
}
原文地址:https://www.cnblogs.com/DefineWaAc/p/14197856.html