CodeForces - 148C Terse princess (构造)
2018-01-08 14:21
483 查看
题目链接:http://codeforces.com/problemset/problem/148/C点击打开链接
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.
Examples
input
output
input
output
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.
题目要求小于50000
2^15==30000+ 因此不会超 但是正是因为这个临界 坑点很多
我们可以这样想 因为最大不会超 因此可以1 2 4 。。吧b的个数造出来
再造a 每次+1
但是因为唯一特殊的2-1=1&&2》sum(1)
因此要判断特殊条件
给几个特例
1 0 0
2 1 0
3 1 0
其中1 0 0 可以构造
但如果存在b=0并且n=a-1 如2 1 0 则不存在 因为必定存在前两个数 第二个数即大于第一个数 又比他总和大
然后如果是b=0且n!=a-1时 则需要先把剩余数输出 使得不会出现前两位的重叠情况
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.
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.
题目要求小于50000
2^15==30000+ 因此不会超 但是正是因为这个临界 坑点很多
我们可以这样想 因为最大不会超 因此可以1 2 4 。。吧b的个数造出来
再造a 每次+1
但是因为唯一特殊的2-1=1&&2》sum(1)
因此要判断特殊条件
给几个特例
1 0 0
2 1 0
3 1 0
其中1 0 0 可以构造
但如果存在b=0并且n=a-1 如2 1 0 则不存在 因为必定存在前两个数 第二个数即大于第一个数 又比他总和大
然后如果是b=0且n!=a-1时 则需要先把剩余数输出 使得不会出现前两位的重叠情况
#include <bits/stdc++.h> using namespace std; int a[111111]; int main() { int n,a,b; cin>>n>>a>>b; if(n==a+1) { if(a!=0) { cout << -1 << endl; return 0; } } if(b==0) { int num=1; int cnt=n-a-b; b++; cnt--; while(cnt--) { cout << "1" << " "; } while(b) { cout << num << " "; b--; if(b) num<<=1; } while(a) { cout << ++num << " "; a--; } return 0; } int num=1; int cnt=n-a-b; b++; cnt--; while(b) { cout << num << " "; b--; if(b) num<<=1; } while(a) { cout << ++num << " "; a--; } while(cnt--) { cout << "1" << " "; } }
相关文章推荐
- Codeforces 628C Bear and String Distance 【构造】
- CodeForces 644 A.Parliament of Berland(构造)
- codeforces 24 Game(数学构造)
- CodeForces - 848A From Y to Y(构造)
- Codeforces 141C【构造】
- Codeforces 916 C. Jamie and Interesting Graph (构造)
- CodeForces 645E Intellectual Inquiry(构造+贪心+dp)
- Codeforces 346C Number Transformation II 构造
- codeforces 123A A. Prime Permutation(数论+构造)
- Codeforces 15D Map 单调队列+构造
- Codeforces 488B - Candy Boxes (构造)
- Codeforces 149C Division Into Teams 构造
- codeforces 743-C. Vladik and fractions(构造)
- 【构造】 Codeforces 476D Dreamoon and Sets
- CodeForces 44J - Triminoes -搜索转构造
- codeforces 782C Andryusha and Colored Balloons【构造】
- Codeforces 482 - Diverse Permutation 构造题
- Codeforces 303A 构造+数论
- codeforces-237【B构造】【C二分】
- 【Codeforces】-297C-Splitting the Uniqueness(构造)