«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 sawn grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence ofn integers t1, t2, ..., tn, whereti describes the fortune ofi-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.
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 any sequence of integers t1, t2, ..., tn, whereti (1 ≤ ti ≤ 50000) is the fortune ofi-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number-1.
10 2 3
5 1 3 6 16 35 46 4 200 99
5 0 0
10 10 6 6 5
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.
题目链接:http://codeforces.com/problemset/problem/148/C
题目大意:n个数的数组,如果当前数字比它前面所有的数字都大,则是情况Oh,情况Oh的数有a个。如果这个数比它前面所有数字的和都大,则是情况Wow,情况Wow的数有b个。构造这样的数组。如果数组不存在,输出-1。
解题思路:二进制思维处理Wow的情况,1 2 4 8 16......每个数都比前面的数字和大,先构造Wow的情况,再构造Oh的情况,最后构造一般情况。注意:1.b=0且普通情况只有一个时不能构造;2.第一个数是普通情况;3.Wow,Oh条件都满足时时Wow情况。
代码如下:
#include <cstdio>
#include <cstring>
int t[105];
int main(void)
{
int n,a,b;
scanf("%d%d%d",&n,&a,&b);
if(!b&&a&&n-a==1)
{
printf("-1\n");
return 0;
}
printf("1");
t[0]=1;
for(int i=1;i<n;i++)
{
if(!b&&i==1)
{
t[1]=1;
printf(" 1");
a++;
continue;
}
if(i<=b)
t[i]=1<<i;
else if(i<=a+b)
t[i]=t[i-1]+1;
else
t[i]=t[i-1];
printf(" %d",t[i] );
}
printf("\n");
}
这篇博客介绍了一个有趣的算法问题:如何为一系列求婚者分配财富值,使得公主能够根据特定规则表达她的满意。通过输入参数n、a和b,读者可以探索如何构造符合公主期望的财富分配序列。了解公主的反应模式,包括她对财富增加的两种不同反馈——'Oh...' 和 'Wow!',并学会如何根据这些规则生成相应的序列。此过程不仅涉及逻辑思考,还考验了对数学和编程能力的理解。
392

被折叠的 条评论
为什么被折叠?



