508C — Anya and Ghosts
来源:互联网 发布:windows 做磁盘条带化 编辑:程序博客网 时间:2024/05/01 05:54
求每一个怪到达的时候都有r个蜡烛在燃烧的最少蜡烛数,这是一个贪心题,只要保证点燃的时间尽量晚就可以。
#include <map>#include <string>#include <sstream>#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;int m,t,r,ans;int a[310],cnt[1010];//cnt记录从午夜之后每个时间点有多少蜡烛燃烧 0 代表midnightint main(){scanf("%d%d%d",&m,&t,&r);for(int i = 0; i < m; i++) scanf("%d",&a[i]);for(int i = 0; i < r; i++){for(int j = max(a[0] - i,0); j < a[0] - i + t; j++){cnt[j]++;}}ans = r;for(int i = 0; i < m; i++){if(cnt[a[i]] == r) continue;if(i == 0){//如果按照最优策略第一个怪都无法满足要求 证明多少蜡烛都不可以 cout << "-1" << endl;return 0;}int tmp = r - cnt[a[i]];//每次不符合 按最优策略补充tmp个蜡烛ans += tmp;for(int j = 0; j < tmp; j++)for(int k = a[i] - j; k < a[i] - j + t; k++)cnt[k]++;}cout << ans << endl;return 0;}
0 0
- 508C — Anya and Ghosts
- Anya and Ghosts - CodeForces 508 C 水题
- Codeforces 508C Anya and Ghosts
- CF 508C(Anya and Ghosts-贪心)
- codeforces 508 C. Anya and Ghosts
- Codeforces 508C Anya and Ghosts【贪心】
- Codeforces 508C - Anya and Ghosts (模拟 + 贪心)
- CodeForce 508C Anya and Ghosts (贪心+模拟)
- codeforces-508C-Anya and Ghosts【贪心】【思维】
- 【CodeForces】508C - Anya and Ghosts(贪心 & 模拟)
- codeforces - 508C - Anya and Ghosts(贪心)
- codeforces--C - Anya and Ghosts(贪心)
- codeforces--C - Anya and Ghosts(贪心+模拟)
- 【codeforce508C】. 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
- JavaScript跨域总结与解决办法
- jquery实现圆点绕圆心循环转动
- [C# 网络编程系列]专题三:自定义Web服务器
- win32 socket阻塞与非阻塞函数及设置
- 图片上添加水印
- 508C — Anya and Ghosts
- 面试题5 从头到尾打印链表
- 兔子-Myeclipse configuration center
- opatch打补丁时遭遇失败
- poj解题报告——1416
- java多态性Overload和Override的区别
- wireshark基本用法及过虑规则
- addSubview和insertSubview 的区别解析
- MySQL在Ubuntu设置自启动的一个故障解决