CodeForces - 148C C - Terse princess 构造数列
来源:互联网 发布:centos mv 移动目录 编辑:程序博客网 时间:2024/05/07 16:36
«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.
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, 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.
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 3546 4 200 99.
- The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 1635 46 4 200 99.
题意:
公主辨别宝物,如果当前宝物价值大于所有之前宝物价值总和就会说wow ,如果大于之前任何一个宝物价值就会说oh,
现在有a个oh b个wow 询问宝物出现价值顺序 这里注意说wow就不会算在oh中
思路:
只要是让我们输出一个序列的都应该先想想构造啊.....为了使最大的尽可能的小,所以要先构造wow ,之后构造oh
我这里的构造是按照2的n次方来构造的,因为其保证后一项会大于前面所有的和;剩下的全部构造为1即可,
题目有几个坑点:
首先我们来说一下什么情况下无法构造序列,当b=0时,并且a!=0并且 n-a==1,因为这里无论怎么构造第二个数都会比第一个大优先wow
其次当n==1时我们也是可以的 输出 1即可
还有当 b==0时 由于我们不能构造出 某项比前面所有和都大的情况,这里需要注意
#include<bits/stdc++.h>
using namespace std;
int t[500];
int a,b,n,x,i;
int main()
{ cin>>n>>a>>b;
if(!b&&a&&n-a==1)
{ printf("-1");
return 0;
}
printf("1");
t[0]=1;
x=2;
for(i=1;i<n;i++)
{
if(b==0&&i==1)
{ t[i]=1;
a++;
}
else if(i<=b)
{ t[i]=x;
x*=2;
}
else if(i<=a+b)
{ t[i]=t[i-1]+1;
}
else
t[i]=1;
}
for(i=1;i<n;i++)
cout<<' '<<t[i];
return 0;
}
- CodeForces - 148C C - Terse princess 构造数列
- codeforces-148C-Terse princess【构造】
- CodeForces 148C - Terse princess
- CodeForces 148C-Terse princess
- Codeforces Round #105 (Div. 2) 148C Terse princess(脑洞)
- codeforces 148C Terse princess(有意思的模拟)
- C. Terse princess
- Codeforces Round #105 (Div. 2) C. Terse princess
- 构造数列Codeforces Round #261 (Div. 2)C
- CodeForces 600C【构造】
- CodeForces 110C 【构造】
- Codeforces 141C【构造】
- CodeForces 828C【构造】
- Codeforces 862C(构造)
- CodeForces 535C(数列处理)
- Codeforces-148C-standard output(构造)
- Codeforces 417C Football(构造)
- Codeforces 489C 简单构造
- 郝斌的C语言基础 165,166 枚举
- android 避免2次点击事件
- Frequentist 观点和 Bayesian 观点
- 最常用的15大Eclipse开发快捷键技巧
- 图像混合(Python+opencv)
- CodeForces - 148C C - Terse princess 构造数列
- 用python实现FTP传输
- 2.2、Hibernate用注解方式实现一对多、多对多关系
- Logger的解析使用
- JAVA设计模式之外观模式
- .实现一个函数,可以左旋字符串中的k个字符。 AABCD左旋一个字符得到ABCDA AABCD左旋两个字符得到BCDAA
- String StringBuiler StringBuffer
- Apache HTTP Server通过mod_cluster模块与Tomcat连接
- JS获取屏幕宽高