Codeforces Round #288 (Div. 2) C. Anya and Ghosts 贪心
2015-08-02 14:40
597 查看
思路:由于一个candle只能覆盖t,所以对某一时刻w[i],最早的candle点亮时间不超过w[i] - t。否则w[i]时刻该candle已经熄灭。
所以对每个w[i],统计w[i] - t ~ w[i] - 1之间有多少根蜡烛被点亮即可。若已有r个candle,不做任何处理。否则,由近及远点亮需要的candle。
代码如下:
所以对每个w[i],统计w[i] - t ~ w[i] - 1之间有多少根蜡烛被点亮即可。若已有r个candle,不做任何处理。否则,由近及远点亮需要的candle。
代码如下:
#include <cstdio> using namespace std; #define N 605 int w ; bool candle ; int main(){ int n, t, r, x; scanf("%d %d %d", &n, &t, &r); for(int i = 1; i <= n; ++i) scanf("%d", &x), w[i] = x + 300; if(t < r) printf("-1\n"); else{ int ans = 0; bool ok = true; for(int i = 1; i <= n && ok; ++i){ int cnt = 0; for(int j = w[i] - 1; j >= w[i] - t; --j){ if(candle[j]) cnt ++; } if(cnt < r){ for(int j = w[i] - 1; j >= w[i] - t && cnt < r; --j){ if(!candle[j]) cnt ++, ans ++, candle[j] = true; } if(cnt < r) ok = false; } } if(ok) printf("%d\n", ans); else printf("-1\n"); } return 0; }
相关文章推荐
- 小贝_redis set/zset类型学习
- 第十二天:数组,异常,常用类,正则表达式
- Scala学习第八天 Scala主构造器、私有构造器、构造器重载实战详解
- COM+应用程序错误(错误代码8004E00F)的解决方法
- PB inet组件 Post给php时怎么接收
- js实现商品团购活动到计时
- Reverse Linked List II
- hdu5316Magician 线段树
- BeautifulSoup的详细笔记
- Oracle用户被锁原因及办法
- Scala学习第六天 Map、Tuple、Zip实战解析
- oracle序列详解
- SQL Server游标的使用【转】
- 用 Spring Security 4+Spring MVC+Spring4 构建健壮且安全的web应用
- php连接java最新能用的方法,javabridge的配置
- C语言面试题
- Scala学习第四天 Scala的For与Function进阶实战、Lazy的使用
- 栈 stack 用数组实现
- Scala学习第三天 Tuple、Array、May与文件操作入门实战
- org.apache.velocity 简介