您的位置:首页 > 编程语言 > PHP开发

Codeforces-148C-standard output(构造)

2017-12-05 21:53 344 查看
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
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.

Examples

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.
题意:构造一个序列,有a个比前面的数都大的数,有b个比前面所有的数的和都大的数

思路:要构造这样的序列,可以选择先确定那b个数,记录前缀和,然后确定a个数,比之前最大的数大一就ok,然后剩下的数全部为1,然后注意一些细节,具体请看代码

AC代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a,b;
int ans[150];
int main()
{
while(~scanf("%d%d%d",&n,&a,&b))
{
if((a+b)==0){//直接倒序输出
for(int i=n;i>=1;i--)
printf("%d%c",i,i==1?'\n':' ');
continue;
}
if(a==n-1){//a最多为n-2,思考一下。。
printf("-1\n");
continue;
}
else if(n==2&&b==1){
printf("1 2\n");
continue;
}
if(b>=1){//根据b的不同确定开头两个数
ans[1]=1;
ans[2]=2;
b--;
}
else{
ans[1]=2;
ans[2]=1;
}
int tmp=3;
int p=3;
for(;b>0;p++)
{
ans[p]=tmp+1;
b--;
if(b)tmp+=ans[p];//b>0时tmp为前缀和
else tmp+=2;//b=0之后+2,比前一个数大一就好

}
for(;a>0;p++)
{
ans[p]=tmp;//a大于0时,每次只要比前面的数大一个就行
tmp++;
a--;
}
for(;p<=n;p++)//剩下的都为1
ans[p]=1;
for(int i=1;i<=n;i++)
printf("%d%c",ans[i],i==n?'\n':' ');
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: