Codeforces Round #105 (Div. 2) 148C Terse princess(脑洞)
1 second
256 megabytes
standard input
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.
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 35 46 4 200 99.
- The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99.
题目链接:点击打开链接
有一个长度为n的序列, 假设一个数比前面的数都大, 则会说Oh, 假设一个数比前面全部数的和都大, 则会说Wow. 现给出Oh数a, Wow数
b, 要求输出一个满足题意的数组, 不存在这种数组则输出-1.
构造一个数组, a[1] = 1, 进行n - 2次操作, 每一次操作都记录当前值和前面数的和, 优先降低b, 为sum + 1, 否则降低a, 为res + 1.
AC代码:
#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
#include "queue"
#include "stack"
#include "cmath"
#include "utility"
#include "map"
#include "set"
#include "vector"
#include "list"
#include "string"
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 105;
int n, a, b, ans[MAXN];
int main(int argc, char const *argv[])
{
scanf("%d%d%d", &n, &a, &b);
ans[1] = 1;
int res = 1, sum = 1;
for(int i = 2; i <= n; ++i) {
if(b) {
res = sum + 1;
b--;
}
else if(a && i > 2) {
res++;
a--;
}
ans[i] = res;
sum += res;
}
if(a || b) {
printf("-1\n");
return 0;
}
for(int i = 1; i < n; ++i)
printf("%d ", ans[i]);
printf("%d\n", ans[n]);
return 0;
}
Codeforces Round #105 (Div. 2) 148C Terse princess(脑洞)的更多相关文章
- 水题 Codeforces Round #105 (Div. 2) B. Escape
题目传送门 /* 水题:这题唯一要注意的是要用double,princess可能在一个小时之内被dragon赶上 */ #include <cstdio> #include <alg ...
- Codeforces Round #105 (Div. 2) ABCDE
A. Insomnia cure 哎 只能说英语太差,一眼题我看了三分钟. 题意:给5个数k, l, m, n 和 d,求1~d中能被k, l, m, n 至少一个整除的数的个数. 题解:…… 代码: ...
- Codeforces Round #105 (Div. 2) D. Bag of mice 概率dp
题目链接: http://codeforces.com/problemset/problem/148/D D. Bag of mice time limit per test2 secondsmemo ...
- Codeforces Round #105 (Div. 2) E. Porcelain —— DP(背包问题)
题目链接:http://codeforces.com/problemset/problem/148/E E. Porcelain time limit per test 1 second memory ...
- codeforces水题100道 第四题 Codeforces Round #105 (Div. 2) A. Insomnia cure (math)
题目链接:http://www.codeforces.com/problemset/problem/148/A题意:求1到d中有多少个数能被k,l,m,n中的至少一个数整出.C++代码: #inclu ...
- Codeforces Round #337 (Div. 2) 610C Harmony Analysis(脑洞)
C. Harmony Analysis time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #383 (Div. 2) 题解【ABCDE】
Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...
- Codeforces Round #182 (Div. 1)题解【ABCD】
Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...
随机推荐
- 优动漫PAINT基础系列之图层模式
在绘画软件优动漫PAINT中,笔刷工具属性中的消除锯齿变成灰色无法选择了?铅笔绘制没有压感?快来改改图层模式~ 优动漫PAINT下载:http://www.dongmansoft.com/xiazai ...
- NetworkX-根据权重画图
load_data = sio.loadmat(load_path) #阈值处理 mat=np.array(load_data['R']) mat[mat<0]=0 mat[mat<0.4 ...
- 虚拟机创建后该如何获取IP地址并访问互联网实用教程
之前在做项目的时候主机IP地址.网关.DNS.子网掩码等都是公司或者对方直接给提供的,但是如果我们自己想搭建一台虚拟机或者一台集群的话,手头又没有IP地址,该肿么办呢? 白慌,这里介绍一个小技巧, ...
- 解决IIS服务器部署 字体图标找不到的原因
引言 我们往往在IIS上部署Web项目,或者发布Web项目的时候,经常会遇到浏览器找不到字体文件(woff/woff2)产生的错误.这样会导致浏览器无法加载字体图标,在影响加载时间的同时,更无法显示对 ...
- centos安装nvidia驱动
大部分 Linux 发行版都使用开源的显卡驱动 nouveau,对于 nvidia 显卡来说,还是闭源的官方驱动的效果更好.最明显的一点是,在使用 SAC 拾取震相的时候,使用官方显卡驱动在刷新界面的 ...
- webpack中optimization 的 runtimeChunk 是干嘛的
结论:把runtime部分的代码抽离出来单独打包 https://developers.google.com/web/fundamentals/performance/webpack/use-long ...
- Vue中两种传值方式
第一种:通过url传参,直接在地址后加? ,通过this.$route.query对象获取 第二种:通过路由传参,修改路由,通过this.$route.params对象获取
- Linux Eslint 命令行
Linux 命令行 ls : 查看所有文件 ls -la : 编列文件并展示权限 sudo chmod 777 -R 文件名 : 文件权限升级 cp : 复制 cp file_na ...
- [TJOI2015]弦论(后缀数组or后缀自动机)
解法一:后缀数组 听说后缀数组解第k小本质不同的子串是一个经典问题. 把后缀排好序后第i个串的本质不同的串的贡献就是\(n-sa[i]+1-LCP(i,i-1)\)然后我们累加这个贡献,看到哪一个串的 ...
- useradd: cannot open /etc/passwd
[root@ftp ~]# useradd -g ftp -s/sbin/nologin liwmuseradd: cannot open /etc/passwd [root@ftp ~]# user ...