CodeForce 508C Anya and Ghosts (贪心+模拟)
2015-02-02 10:59
495 查看
题目大意:有m个时刻,在第i时刻即wi秒的时候需要保持有r根蜡烛亮着,每根蜡烛维持的时间为t秒,点一根蜡烛需要1秒。
注意:一根蜡烛亮的时间为下一秒开始。并且一开始是可以事先准备蜡烛的。
想法:利用了优先队列,维护r根蜡烛,每次wi秒,它需要开始点蜡烛的最晚时间为wi-t,如果不够这个时间,那么在最晚结束点蜡烛的时间wi-1开始补上。
感谢阿扎夫人提供的思维题。
AC代码:
注意:一根蜡烛亮的时间为下一秒开始。并且一开始是可以事先准备蜡烛的。
想法:利用了优先队列,维护r根蜡烛,每次wi秒,它需要开始点蜡烛的最晚时间为wi-t,如果不够这个时间,那么在最晚结束点蜡烛的时间wi-1开始补上。
感谢阿扎夫人提供的思维题。
AC代码:
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<queue> #include<functional> #include<vector> #include<cstdio> using namespace std; priority_queue<int, vector<int>, greater<int> > q; int main() { int m, t, r; int w[333]; while (cin >> m >> t >> r) { for (int i = 1; i <= m; i++) scanf("%d", &w[i]); while (!q.empty()) q.pop(); if (t < r) { cout << "-1" << endl; continue; } int start, end; int sum = 0; int mid; while (sum < r) { q.push(-500); sum++; } sum = 0; for (int i = 1; i <= m; i++) { start = w[i]-t; end = w[i] - 1; while (!q.empty() && q.top() < start) { q.push(end); q.pop(); end--; sum++; } } cout << sum << endl; } }
相关文章推荐
- Codeforces 508C - Anya and Ghosts (模拟 + 贪心)
- Codeforces Round #288 (Div. 2)C. Anya and Ghosts(模拟+贪心)
- 【CodeForces】508C - Anya and Ghosts(贪心 & 模拟)
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟 贪心
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
- codeforces--C - Anya and Ghosts(贪心+模拟)
- codeforces-508C-Anya and Ghosts【贪心】【思维】
- Codeforces 508C Anya and Ghosts【贪心】
- CF 508C(Anya and Ghosts-贪心)
- codeforces - 508C - Anya and Ghosts(贪心)
- [CF #288-C] Anya and Ghosts (贪心)
- Codeforces Round #288 (Div. 2)---C. Anya and Ghosts
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts(贪心)
- CF Anya and Ghosts (贪心)
- codeforces--C - Anya and Ghosts(贪心)
- Codeforces Round #331 (Div. 2)-Wilbur and Array(贪心模拟)
- 【codeforces 508C】Anya and Ghosts
- 508C — Anya and Ghosts
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟
- Codeforces 508C Anya and Ghosts