codeforces-148C-Terse princess【构造】

来源:互联网 发布:学闽南话的软件 编辑:程序博客网 时间:2024/05/16 18:50

148C-Terse princess


                time limit per test1 second     memory limit per test256 megabytes

«Next please», — the princess called and cast an estimating glance at the next groom.

The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh…». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh…» in this case). At the sight of the first groom the princess stays calm and says nothing.

The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh…» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1, t2, …, tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1.

Input
The only line of input data contains three integer numbers n, a and b (1 ≤ n ≤ 100, 0 ≤ a, b ≤ 15, n > a + b), separated with single spaces.

Output
Output any sequence of integers t1, t2, …, tn, where ti (1 ≤ ti ≤ 50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1.

input
10 2 3
output
5 1 3 6 16 35 46 4 200 99

input
5 0 0
output
10 10 6 6 5

题目链接:cf-148C

题目大意:构造一个n长度的序列,使得有a个”WOW”,b个“OH”。

WOW:该数字比前面所有数字的和还要大

OH:该数字比前一位数字大

题目思路:我的构造思路是,先输出一个1,然后2 4 8 输出WOW部分,再输出OH部分

输出-1的情况:n = a + 1 && b == 0 && n!= 1

另外,如果b == 0,则先输出 1 1然后输出a部分

以下是代码:

#include <iostream>#include <cstdio>#include <cmath>#include <vector>#include <cstring>#include <algorithm>#include <string>#include <set>#include <functional>#include <numeric>#include <sstream>#include <stack>#include <map>#include <queue>#include<iomanip>using namespace std;vector <int> ans;int main(){    int n,b,a;    cin >> n >> a >> b;    if (n == a + 1 &&b == 0 && n != 1)    {        cout << -1 << endl;        return 0;    }    if (b == 0 && a != 0)    {        int sum = 1;        ans.push_back(1);        ans.push_back(1);        for (int i = 1; i <= a; i++)        {            sum++;            ans.push_back(sum);        }        for (int i = 1; i <= n - a - b; i++) ans.push_back(1);        cout << ans[0];        for (int i = 1; i < n; i++) cout << " " << ans[i];        cout << endl;        return 0;    }    int sum = 1;    ans.push_back(1);    for (int i = 1; i <= b; i++)    {        sum *= 2;        ans.push_back(sum);    }    for (int i = 1; i <= a; i++)    {        sum++;        ans.push_back(sum);    }    if (sum > 50000)    {        cout << -1 << endl;        return 0;    }    for (int i = 1; i <= n - a - b; i++) ans.push_back(1);    cout << ans[0];    for (int i = 1; i < n; i++) cout << " " << ans[i];    cout << endl;    return 0;}
0 0