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 ...
随机推荐
- 第二百五十三、四、五天 how can I 坚持
出去玩了几天,好累啊. 周五,坐了半天车.到了西柏坡,下午撕名牌,好疯狂啊,最终还是以有人受伤为代价结束了战斗.晚上吃蛋糕.水饺,还有面条,就是我的奖品没拿到.哎.. 周六,上午滑雪,两年没滑了,都忘 ...
- [转] GCC 中的编译器堆栈保护技术
以堆栈溢出为代表的缓冲区溢出已成为最为普遍的安全漏洞.由此引发的安全问题比比皆是.早在 1988 年,美国康奈尔大学的计算机科学系研究生莫里斯 (Morris) 利用 UNIX fingered 程序 ...
- 终于弄好了 homework-09
近一周的时间,顶着编译大作业严重搁置的压力,天天搞,终于把网页动态展示的搞出来了!恩,还挺好看~ 因为是最后一次作业了,也是因为天生的完美主义强迫症,做到自己满意才放心停下来.不过,这个过程,看着同学 ...
- F5 刷新功能
//1.引入单元 uses ShlObj; //2.执行命令 procedure TForm1.Button1Click(Sender: TObject); begin SHChangeNotify( ...
- 11235 - Frequent values
<算法竞赛入门经典-训练指南>P198 记录一下区间的左右边界就可以了 #include <iostream> #include <stack> #include ...
- C语言快排
C语言使用快排的方式有两种,1.直接用库函数stdlib.h里的qsort函数 2.自己编写快排代码(第一种方便,第二种较为自由) qsort 的函数原型是:void qsort(void*base, ...
- Linux下通过JDBC连接Oracle,SqlServer和PostgreSQL
今天正好需要统计三个网站栏目信息更新情况,而这三个网站的后台采用了不同的数据库管理系统.初步想法是通过建立一个小的Tomcat webapp,进而通过JDBC访问这三个后台数据库,并根据返回的数据生成 ...
- UVa442 Matrix Chain Multiplication
// UVa442 Matrix Chain Multiplication // 题意:输入n个矩阵的维度和一些矩阵链乘表达式,输出乘法的次数.假定A和m*n的,B是n*p的,那么AB是m*p的,乘法 ...
- BW性能优化
少写例程,减少ABAP处理时间,例程要有效率减少查询数据库表先加载主数据,然后加载事务数据创建聚集进行数据压缩M:N关系的数据不能放到一个维度减少计算指标数量,提高上载效率并行加载建模型时如果有日的分 ...
- BW导航属性设置
BW中的Attribute(属性)分为Display Att.和Navigation(导航) Att.,这里我就简称Dis. att和Nav. att了,导航属性可以做为变量来查询和做限制 1.首先进 ...