508C — Anya and Ghosts
2015-02-03 18:34
316 查看
求每一个怪到达的时候都有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 代表midnight int 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; }
相关文章推荐
- CodeForce 508C Anya and Ghosts (贪心+模拟)
- 【CodeForces】508C - Anya and Ghosts(贪心 & 模拟)
- 【codeforces 508C】Anya and Ghosts
- codeforces-508C-Anya and Ghosts【贪心】【思维】
- codeforces - 508C - Anya and Ghosts(贪心)
- Codeforces 508C Anya and Ghosts【贪心】
- Codeforces 508C - Anya and Ghosts (模拟 + 贪心)
- Codeforces 508C Anya and Ghosts
- CF 508C(Anya and Ghosts-贪心)
- 【codeforce508C】. 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 508 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
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts