codeforces 148C Terse princess(有意思的模拟)
2017-12-05 22:34
866 查看
«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.
Example
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.
题解:
我的思路是从1开始,先模拟wow的情况,也就是a[i]=s+1,再模拟oh的情况,a[i]=a[i-1]+1,如果循环完还剩就-1,然后wa了一发看了数据19 1 0这种我输出是-1,但是是有答案的,就只要当wow的个数放完后放oh的时候特判当前前面的和s是否大于将要放进去的a[i]=a[i-1]+1,如果大了就慢点放,用a[i]=a[i-1]先将s撑大一些再放,如果循环完num1和num2有剩余,就输出-1
代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<stdlib.h>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<stdio.h>
using namespace std;
#define ll long long
int a[105];
int main()
{
int num1,num2,i,j,s=1,n;
scanf("%d%d%d",&n,&num1,&num2);
a[0]=1;
for(i=1;i<n;i++)
{
if(num2)
{
a[i]=s+1;
num2--;
}
else if(num1)
{
a[i]=a[i-1]+1;
if(s<a[i])
{
a[i]=a[i-1];
}
else
num1--;
}
else
a[i]=a[i-1];
s+=a[i];
}
if(num1||num2)
printf("-1\n");
else
{
printf("%d",a[0]);
for(i=1;i<n;i++)
printf(" %d",a[i]);
printf("\n");
}
return 0;
}
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.
Example
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.
题解:
我的思路是从1开始,先模拟wow的情况,也就是a[i]=s+1,再模拟oh的情况,a[i]=a[i-1]+1,如果循环完还剩就-1,然后wa了一发看了数据19 1 0这种我输出是-1,但是是有答案的,就只要当wow的个数放完后放oh的时候特判当前前面的和s是否大于将要放进去的a[i]=a[i-1]+1,如果大了就慢点放,用a[i]=a[i-1]先将s撑大一些再放,如果循环完num1和num2有剩余,就输出-1
代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<stdlib.h>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<stdio.h>
using namespace std;
#define ll long long
int a[105];
int main()
{
int num1,num2,i,j,s=1,n;
scanf("%d%d%d",&n,&num1,&num2);
a[0]=1;
for(i=1;i<n;i++)
{
if(num2)
{
a[i]=s+1;
num2--;
}
else if(num1)
{
a[i]=a[i-1]+1;
if(s<a[i])
{
a[i]=a[i-1];
}
else
num1--;
}
else
a[i]=a[i-1];
s+=a[i];
}
if(num1||num2)
printf("-1\n");
else
{
printf("%d",a[0]);
for(i=1;i<n;i++)
printf(" %d",a[i]);
printf("\n");
}
return 0;
}
相关文章推荐
- Codeforces 792D Paths in a Complete Binary Tree 规律+模拟
- CodeForces - 758D Ability To Convert(模拟,递归)
- Codeforces 876 D. Sorting the Coins 模拟
- Codeforces Good Bye 2017 908F - New Year and Rainbow Roads 贪心+模拟
- CodeForces 493C Vasya and Basketball(模拟 + 二分)
- CodeForces 3C Tic-tac-toe(模拟)
- CodeForces - 368C Sereja and Algorithm (找规律&模拟)
- Codeforces 350 Div2 E Correct Bracket Sequence Editor(list模拟)
- codeforces 676b 模拟
- CodeForces - 673A Bear and Game (模拟)水
- codeforces 878B B. Teams Formation 模拟
- Codeforces 797C Minimal String 贪心+模拟
- 【STL】【模拟】Codeforces 696A Lorenzo Von Matterhorn
- CodeForces 471B MUH and Important Things 模拟 水
- CodeForces 90B African Crossword【模拟】
- Codeforces--616A--Comparing Two Long Integers(模拟水题)
- 【模拟】Codeforces 699B One Bomb
- CodeForces 670B(模拟)水题
- 【模拟】【codeforces】451A Game With Sticks
- 【CodeForces】632B - Alice, Bob, Two Teams(模拟)