UVA 11292 - Dragon of Loowater
2017-09-06 09:16
316 查看
题目大意:氪金勇者斗恶龙,有n头恶龙,m个勇者,一个勇者只能斗一头龙,每头恶龙和每个勇者都有能力值,只有勇者的能力值不低于恶龙的能力值时才打得过。问,能否打完全部恶龙,能的话至少需要多少金币,出战的勇者能力值与需要的金币数一致。
解题思路:贪心,排序恶龙勇者能力值。从勇者小的往上推,当大于等于恶龙时,金币数增加,恶龙增加,勇者增加,屠龙数增加。最后判断屠龙数是否等于恶龙数。
ac代码:
解题思路:贪心,排序恶龙勇者能力值。从勇者小的往上推,当大于等于恶龙时,金币数增加,恶龙增加,勇者增加,屠龙数增加。最后判断屠龙数是否等于恶龙数。
ac代码:
#include <iostream> #include <algorithm> using namespace std; int main() { int n, m, a[20005], b[20005], sum, cnt; while (scanf("%d%d", &n, &m)!=EOF && n && m){ sum = cnt = 0; for (int i=0; i<n; i++) scanf("%d", &a[i]); for (int i=0; i<m; i++) scanf("%d", &b[i]); sort(a, a+n); sort(b, b+m); for (int i=0,j=0; i<n && j<m; j++) if (b[j] >= a[i]) sum += b[j], i++, cnt++; if (cnt == n) printf("%d\n", sum); else printf("Loowater is doomed!\n"); } return 0; }
相关文章推荐
- Uva 11292 Dragon of Loowater - 水题
- 【UVa】11292 - Dragon of Loowater
- UVa11292 Dragon of Loowater
- UVA 11292 The Dragon of Loowater
- UVA 11292 A-Dragon of Loowater
- UVa11292 The Dragon of Loowater
- UVA - 11292 Dragon of Loowater
- UVA 11292 Dragon of Loowater
- UVa 11292 Dragon of Loowater——思路题
- Uva 11292 The Dragon of Loowater 模拟题
- UVA - 11292 - Dragon of Loowater
- UVa-11292 Dragon of Loowater (贪心)
- 贪心/思维题 UVA 11292 The Dragon of Loowater
- uva11292 Dragon of Loowater
- Uva 11292 Dragon of Loowater (贪心)
- UVa 11292 Dragon of Loowater
- UVa - 11292 - Dragon of Loowater 算法题解
- uva11292 Dragon of Loowater 水题
- UVA 11292 Dragon of Loowater(简单贪心)
- UVA 11292 - The Dragon of Loowater (water)