• Terse princess CodeForces


    «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.

    Example

    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

    题意:构造出这样的一种数列,数列中有a个比前面所有的数都大的数,有b个比前面所有的数的和都大的数。
    坑点:n = a + 1时构造不出;n = 1的情况;把小数放在序列的末尾
    题解:试了很久,先构造出b个WOW(1 2 4 8 16 32 ····),然后是a个Oh,最后添加1。如果序列先打印1,会超过50000!!!
     1 // ConsoleApplication2.cpp: 定义控制台应用程序的入口点。
     2 //
     3 
     4 #include "stdafx.h"
     5 #include<cmath>
     6 #include<queue>
     7 #include<cstdio>
     8 #include<cstring>
     9 #include<iostream>
    10 #include<algorithm>
    11 using namespace std;
    12 
    13 const int maxn = 1005;
    14 
    15 int n, a, b;17 
    18 int main()
    19 {
    20     while (scanf_s("%d%d%d", &n, &a, &b) != EOF) {
    21         int sum = n - (a + b);
    22         if (n == 1) { cout << 1 << endl; continue; }
    23         if (n == a + 1) { cout << -1 << endl; continue; }
    24         if (b == 0) {
    25             cout << 1;
    26             for (int i = 0; i < sum - 1; i++) cout << " " << 1;
    27             for (int i = 0; i < a; i++) cout << " " << sum++;
    28             cout << endl;
    29         }
    30         else {
    31             cout << 1;
    32             int t = 1;
    33             for (int i = 0; i < b; i++) {
    34                 t += t;
    35                 cout << " " << t;
    36             }
    37             for (int i = 0; i < a; i++) {
    38                 t ++;
    39                 cout << " " << t;
    40             }
    41             for (int i = 0; i < sum - 1; i++) {
    42                 cout << " " << 1;
    43             }
    44             cout << endl;
    45         }
    46     }
    47     return 0;
    48 }
  • 相关阅读:
    首页三级菜单显示
    mysql引擎(转)
    nginx配置虚拟主机
    macos10.9 配置nginx,php-fpm
    排序算法 java实现
    Struts清楚session方法
    No result defined for action and result input的错误
    java throw throws
    try catch finally中return语句与非return语句的执行顺序问题
    java操作Excel
  • 原文地址:https://www.cnblogs.com/zgglj-com/p/8505649.html
Copyright © 2020-2023  润新知