UVa 11292:Dragon of Loowater(水题)
2015-09-26 09:29
537 查看
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=456&page=show_problem&problem=2267
题意:你的王国里有一条n个头的恶龙,你希望雇一些骑士把它杀死(即砍掉所有头)。村里有m个骑士可以雇佣,一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x个金币。如何雇佣骑士才能砍掉恶龙的所有头,且需要支付的金币最少?注意,一个骑士只能砍一个头(且不能被雇佣两次)。(本段摘自《算法竞赛入门经典(训练指南)》
分析:
水题。直接排序搞就好了。
代码:
题意:你的王国里有一条n个头的恶龙,你希望雇一些骑士把它杀死(即砍掉所有头)。村里有m个骑士可以雇佣,一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x个金币。如何雇佣骑士才能砍掉恶龙的所有头,且需要支付的金币最少?注意,一个骑士只能砍一个头(且不能被雇佣两次)。(本段摘自《算法竞赛入门经典(训练指南)》
分析:
水题。直接排序搞就好了。
代码:
#include <iostream> #include <fstream> #include <algorithm> #include <cmath> #include <cctype> #include <string> using namespace std; const int maxn = 20000 + 5, INF = 2000005; int n, m, ans, cnt; int a[maxn], b[maxn]; int main() { while (~scanf("%d%d", &n, &m), n || m) { for (int i = 0; i < n; ++i) scanf("%d", &a[i]); for (int i = 0; i < m; ++i) scanf("%d", &b[i]); if (n > m) printf("Loowater is doomed!\n"); else { sort(a, a + n); sort(b, b + m); cnt = 0; ans = 0; for (int i = 0; i < m; ++i) if (b[i] >= a[cnt]) { ++cnt; ans += b[i]; if (cnt == n) break; } if (cnt == n) printf("%d\n", ans); else printf("Loowater is doomed!\n"); } } return 0; }
相关文章推荐
- The Knuth-Morris-Pratt Algorithm
- OC 类目(category) 延展(extension) 协议(protocol)
- the heapsort algorithm
- Going asynchronous: from Flask to Twisted Klein
- Golang基于学习总结
- OC基础-Category的用法
- django实现文件上传
- POJ3623:Best Cow Line, Gold(后缀数组)
- Django模板中日期过滤器的问题
- golang使用interface来mock进行测试(来自dotGO2014)
- 网页中调用Google地图
- 最大生成树POJ2263Heavy Cargo解题报告
- Windows 使用pip安装 Django
- 动态链接库中函数的地址确定---PLT和GOT [转]
- 欧拉函数之HDU4983 Goffi and GCD
- Go 中的反射要点
- Logo常用的12种颜色
- Django Meta内部类选项
- GoldenGate
- Django中更新多个对象数据与删除对象的方法