Codeforces Round #288 (Div. 2) C. Anya and Ghosts(贪心)
来源:互联网 发布:斜面小车 能测几组数据 编辑:程序博客网 时间:2024/05/16 18:32
Anya loves to watch horror movies. In the best traditions of horror, she will be visited bym ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactlyt 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 exactlyt 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: thei-th visit will happen wi seconds after midnight, allwi'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 leastr 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 numberswi (1 ≤ i ≤ m,1 ≤ wi ≤ 300), thei-th of them repesents at what second after the midnight thei-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 310
3
2 10 15 8
1
1 1 310
-1
-----------------------------------------------
题意:
m个鬼,每个鬼到来持续一秒,需要r盏蜡烛,求出每个鬼到来的时候都有r盏蜡烛的最少需蜡烛数,无法实现时输出-1。
思路:
蜡烛在鬼到来的前一秒点燃最佳,如果每一个鬼到来的时候没有足够的蜡烛,则从那一时刻往前面增加蜡烛。
CODE:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int g[10005], cnt[10005];int main(){//freopen("in", "r", stdin); int m, t, r; while(~scanf("%d %d %d", &m, &t, &r)) { memset(cnt, 0, sizeof(cnt)); for(int i = 0; i < m; ++i) { scanf("%d", &g[i]); } if(t < r) { printf("-1\n"); continue; } int ans = 0; for(int i = 0; i < m; ++i) { for(int j = g[i] - 1; cnt[g[i]] < r; --j) { for(int k = j + 1; k <= j + t; ++k) { if(k >= 0) cnt[k]++; } ans++; } } printf("%d\n", ans); } return 0;}
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts 贪心
- C. Anya and Ghosts(Codeforces Round #288 (Div. 2))
- Codeforces Round #288 (Div. 2)C. Anya and Ghosts(模拟+贪心)
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts(贪心)
- Codeforces Round #288 (Div. 2)---C. Anya and Ghosts
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts
- C. Anya and Ghosts( Codeforces Round #288 (Div. 2))
- Codeforces Round #288 (Div. 2)C. Anya and Ghosts
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts
- codeforces--C - Anya and Ghosts(贪心)
- codeforces--C - Anya and Ghosts(贪心+模拟)
- Codeforces 508C Anya and Ghosts【贪心】
- 【CodeForces】508C - Anya and Ghosts(贪心 & 模拟)
- codeforces - 508C - Anya and Ghosts(贪心)
- C. Anya and Ghosts(Codeforces Round #288(div2)
- Codeforces 508C - Anya and Ghosts (模拟 + 贪心)
- HDU 1114 Piggy-Bank
- CentOS/Linux 自动同步服务器时间
- java.lang.IllegalStateException: Failed to load ApplicationContext
- CSS3学习笔记(上)
- 如何在rails项目中使用grunt
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts(贪心)
- 一致性哈希环
- Model相关:JTable 与JTree
- 代码大全第二版读书笔记 第三部分-变量 十一、变量名的力量
- domino 视图 bs 漂亮显示
- ASP.NET通过配置Web.config中数据库连接地址并封装一个类来简化数据源配置
- OOP四个基本特征,也是面向对象设计的基石
- extern与头文件(*.h)的区别和联系
- imtophat