CF Anya and Ghosts (贪心)
2 seconds
256 megabytes
standard input
standard output
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.
For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.
What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit.
The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that.
If that is impossible, print - 1.
1 8 3
10
3
2 10 1
5 8
1
1 1 3
10
-1 一直WA,果然是题意理解错了,如果第i秒点蜡烛,那么蜡烛会在i+1到i+t的时间段亮,被我理解到i+1+t,唉还指着那句话跟队友说。
贪心策略就是尽可能晚点蜡烛,因为点早了没意义,晚点还可以为后续的幽灵提供照明,所以尽可能在靠近幽灵到达的时间来点。
#include <bits/stdc++.h>
using namespace std; const int INF = -;
int main(void)
{
int m,t,r;
int s[];
int candle[];
int sum,cur; cin >> m >> t >> r;
for(int i = ;i < m;i ++)
cin >> s[i];
if(t - r < )
puts("-1");
else
{
sum = ;
fill(candle,candle + ,INF);
for(int i = ;i < m;i ++)
{
cur = ;
for(int j = ;j < r;j ++)
if(candle[j] + t < s[i])
{
candle[j] = s[i] - cur - ;
cur ++;
sum ++;
}
}
printf("%d\n",sum);
} return ;
}
CF Anya and Ghosts (贪心)的更多相关文章
- [CF #288-C] Anya and Ghosts (贪心)
题目链接:http://codeforces.com/contest/508/problem/C 题目大意:给你三个数,m,t,r,代表晚上有m个幽灵,我有无限支蜡烛,每支蜡烛能够亮t秒,房间需要r支 ...
- CodeForces 508C Anya and Ghosts 贪心
做不出题目,只能怪自己不认真 题目: Click here 题意: 给你3个数m,t,r分别表示鬼的数量,每只蜡烛持续燃烧的时间,每个鬼来时要至少亮着的蜡烛数量,接下来m个数分别表示每个鬼来的时间点( ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟 贪心
C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CodeForces 508C Anya and Ghosts
Anya and Ghosts Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u S ...
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟
C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CF 115B Lawnmower(贪心)
题目链接: 传送门 Lawnmower time limit per test:2 second memory limit per test:256 megabytes Description ...
- CF Soldier and Badges (贪心)
Soldier and Badges time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- cf 853 A planning [贪心]
题面: 传送门 思路: 一眼看得,这是贪心[雾] 实际上,我们要求的答案就是sigma(ci*(ti-i))(i=1~n),这其中sigma(ci*i)是确定的 那么我们就要最小化sigma(ci*t ...
随机推荐
- 微服务、SOA 和 API:是敌是友?
为一个正在不断发展的企业对比关键的集成与应用程序架构概念 对比微服务架构和面向服务的架构(SOA)是一个敏感的话题,常常引起激烈的争论.本文将介绍这些争论的起源,并分析如何以最佳方式解决它们.然后进一 ...
- 报表服务框架:WEB前端UI
1.Highcharts 2.ECharts 3.ichartjs 参考: http://v1.hcharts.cn/index.php http://echarts.baidu.com/ http: ...
- ocp 1Z0-047 131-276题解析
131. Which view would you use to display the column names and DEFAULT valuesfor a table?A. DBA_TABLE ...
- [iOS UI进阶 - 1] 自定义控件
A.关于Quiartz2D的一些细节 1.UIKit的工具已经封装了上下文引用,所以不用手动获取和渲染 - (void)drawRect:(CGRect)rect { [[UIColor redCol ...
- [iOS基础控件 - 6.10] Notification 通知机制
A.定义 iOS程序都有一个NSNotificationCenter的单例对象,用来负责发布不同对象之间的通知 任何对象都能够在NSNotificationCenter发布通知,发 ...
- java封装对象转json字符串
/** * Copyright (c) 2011-2015, James Zhan 詹波 (jfinal@126.com). * * Licensed under the Apache License ...
- mybatis杂记
mybatis学习官网: 1.如果项目中使用maven管理,又引用 了mybatis框架, 下面是mybatis官网给出的 mybatis在maven中央仓库的坐标原文 详情见连接:https://c ...
- Linux设置禁止用户登陆
Linux设置禁止用户登陆 vim /etc/shadow 第二栏(密码栏)设为*,会丢失密码 usermod -L username # -L Lock; -U Unlock chsh userna ...
- WebView自适应并嵌套在ScrollView里
大致思路:通过流的形式把网页抓取下来,然后对webView进行设置. 1.对webView进行设置 web.setWebViewClient(new WebViewClient() { @Overri ...
- 在Mac OS X 10.9上安装nginx
1. 安装PCRE Download latest PCRE. After download go to download directory from terminal. $ cd ~/Downlo ...