• Codeforces Round #105 (Div. 2) 148C Terse princess(脑洞)


    C. Terse princess
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

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

    Sample test(s)
    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
    Note

    Let's have a closer look at the answer for the first sample test.

    • The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99.
    • The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99.


    题目链接:点击打开链接

    有一个长度为n的序列, 假设一个数比前面的数都大, 则会说Oh, 假设一个数比前面全部数的和都大, 则会说Wow. 现给出Oh数a, Wow数

    b, 要求输出一个满足题意的数组, 不存在这种数组则输出-1.

    构造一个数组, a[1] = 1, 进行n - 2次操作, 每一次操作都记录当前值和前面数的和, 优先降低b, 为sum + 1, 否则降低a, 为res + 1.

    AC代码:

    #include "iostream"
    #include "cstdio"
    #include "cstring"
    #include "algorithm"
    #include "queue"
    #include "stack"
    #include "cmath"
    #include "utility"
    #include "map"
    #include "set"
    #include "vector"
    #include "list"
    #include "string"
    using namespace std;
    typedef long long ll;
    const int MOD = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    const int MAXN = 105;
    int n, a, b, ans[MAXN];
    int main(int argc, char const *argv[])
    {
    	scanf("%d%d%d", &n, &a, &b);
    	ans[1] = 1;
    	int res = 1, sum = 1;
    	for(int i = 2; i <= n; ++i) {
    		if(b) {
    			res = sum + 1;
    			b--;
    		}
    		else if(a && i > 2) {
    			res++;
    			a--;
    		}
    		ans[i] = res;
    		sum += res;
    	}
    	if(a || b) {
    		printf("-1
    ");
    		return 0;
    	}
    	for(int i = 1; i < n; ++i)
    		printf("%d ", ans[i]);
    	printf("%d
    ", ans[n]);
    	return 0;
    }



  • 相关阅读:
    CPDA之时间序列
    CSS clear
    27 款经典的CSS 框架
    IT人必读:请不要做浮躁的IT人
    23个Javascript弹出窗口特效
    三种东西永远不要放到数据库里
    jquery 插件 thickbox窗口 第一个控件获得焦点(解决第二次弹出窗口,文本不能输入数据)
    enum总结
    vs版本的选择
    iPhone iPad 各种控件默认高度
  • 原文地址:https://www.cnblogs.com/yjbjingcha/p/7158598.html
Copyright © 2020-2023  润新知