【HDOJ】4544 湫湫系列故事——消灭兔子
2014-12-24 15:57
218 查看
贪心,普通贪心两层循环TLE了,然后用优先级队列维护内层。
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <queue> #include <algorithm> using namespace std; #define MAXN 100005 typedef struct arrow_t { int p, d; bool operator < (const arrow_t &x) const { return p > x.p; } } arrow_t; int B[MAXN]; arrow_t arrows[MAXN]; int n, m; bool comp(arrow_t a, arrow_t b) { return a.d < b.d; } int main() { int i, j, k; __int64 ans; arrow_t arr; bool flag; #ifndef ONLINE_JUDGE freopen("data.in", "r", stdin); #endif while (scanf("%d %d", &n, &m) != EOF) { for (i=0; i<n; ++i) scanf("%d", &B[i]); for (i=0; i<m; ++i) scanf("%d", &arrows[i].d); for (i=0; i<m; ++i) scanf("%d", &arrows[i].p); sort(B, B+n); sort(arrows, arrows+m, comp); ans = 0; priority_queue<arrow_t> Q; k = m-1; flag = true; for (i=n-1; i>=0; --i) { while (k>=0 && arrows[k].d>=B[i]) { Q.push(arrows[k]); --k; } if (Q.empty()) { flag = false; break; } arr = Q.top(); Q.pop(); ans += arr.p; } if (flag) { printf("%I64d\n", ans); } else { printf("No\n"); } } return 0; }
相关文章推荐
- 腾讯马拉松复赛第三场,HDOJ-4544 - 湫湫系列故事——消灭兔子
- hdu-4544-湫湫系列故事——消灭兔子-贪心+stl
- hdu 4544 湫湫系列故事——消灭兔子, 贪心算法+小顶堆
- hdu 4544 湫湫系列故事——消灭兔子 优先队列+贪心
- HDU 4544 湫湫系列故事——消灭兔子(优先队列+贪心)
- HDU 4544 湫湫系列故事——消灭兔子
- HDU 4544 湫湫系列故事——消灭兔子 (贪心+优先队列)
- hdu 4544 湫湫系列故事——消灭兔子
- HDU 4544 湫湫系列故事――消灭兔子
- hdu 4544 湫湫系列故事——消灭兔子 贪心+优先队列 解题报告
- HDU 4544 湫湫系列故事——消灭兔子
- hdu 4544 湫湫系列故事——消灭兔子
- HDU 4544|湫湫系列故事——消灭兔子|平衡树|优先队列|STL
- HDU 4544 湫湫系列故事——消灭兔子
- HDU 4544 湫湫系列故事——消灭兔子
- [优先队列]HDU 4544 湫湫系列故事——消灭兔子
- HDU-4544湫湫系列故事——消灭兔子
- HDU-4544-湫湫系列故事——消灭兔子
- HDU 4544 湫湫系列故事——消灭兔子
- HDU 4544 湫湫系列故事――消灭兔子(优先队列)