UVA 11292 The Dragon of 贪心
来源:互联网 发布:网络用语233是什么意思 编辑:程序博客网 时间:2024/04/27 16:36
题意是 一个龙有n个头 头都有直径 有m个骑士 骑士有身高 如果身高超过直径 骑士就能砍下龙头 一个骑士只能砍一个头 国王雇佣骑士 价格是骑士的身高 求国王最少要多少钱才能杀掉龙 如果杀不掉 就输出 Loowater is doomed!
贪心思想,直接骑士和龙头都从小到大排,从最小的骑士开始选去砍龙头。。
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; const int MAXN = 20005; int n, m, d[MAXN], k[MAXN], ans; void init() { ans = 0; for (int i = 0; i < n; i ++) scanf("%d", &d[i]); for (int i = 0; i < m; i ++) scanf("%d", &k[i]); } void solve() { init(); sort(d, d + n); sort(k, k + m); int j = 0; for (int i = 0; i < m; i ++) { if (k[i] >= d[j]) { ans += k[i]; j ++; if (j == n) { printf("%d\n", ans); return; } } } printf("Loowater is doomed!\n"); } int main() { while (~scanf("%d%d", &n, &m) && n + m) { solve(); } return 0; }
0 0
- UVA 11292 The Dragon of 贪心
- UVa - 11292 - The Dragon of Loowater ( 贪心 )
- The Dragon of Loowater UVa 11292(排序后贪心)
- Uva---11292Problem C: The Dragon of Loowater (贪心)
- UVa 11292 The Dragon of Loowater (贪心)
- UVa 11292&HDU1902 The Dragon of Loowater (贪心)
- uva 11292 - Dragon of Loowater(贪心)
- uva - 11292 - Dragon of Loowater(贪心)
- UVa 11292 - Dragon of Loowater(贪心)
- UVa 11292 - Dragon of Loowater[贪心]
- UVA - 11292 Dragon of Loowater (贪心)
- UVA 11292 DRAGON OF LOOWATER 【贪心】
- UVa Dragon of Loowater 11292 (贪心)
- UVa 11292 - Dragon of Loowater(排序贪心)
- UVA 11292 Dragon of Loowater(贪心)
- UVA 11292 Dragon of Loowater 贪心 .
- UVa - 11292 - Dragon of Loowater ( 排序 + 贪心 )
- UVA.11292 Dragon of Loowater (贪心)
- 操作系统总结
- 《编写可阅读代码的艺术》读书笔记(三)
- 成员变量在构造器之后
- 河南省第三届ACM程序设计大赛题解
- 欢迎使用CSDN-markdown编辑器
- UVA 11292 The Dragon of 贪心
- 【人生随感】平复心情。
- 观察者模式
- 递归与栈
- 【算法设计-优先队列】优先队列的实现与操作
- 学习小结
- 使用
- 反射之获取对象信息
- 入门书籍推荐