UVa 11292 The Dragon of Loowater 勇者斗恶龙
来源:互联网 发布:最新网络流行词2016 编辑:程序博客网 时间:2024/05/17 06:46
题意:你需要雇佣m个骑士去杀死一个有n个头的龙,每个骑士有一个能力值x。能力值为x的骑士可以砍掉一个直径<=x的头,且需要花费x去雇佣。每个骑士最多只能被雇用一次。求杀死龙的最小花费。
典型贪心。将龙头的直径和骑士的能力值分别从小到大排序,从小到大砍龙头。贪心准则是每一个龙头用拥有最接近它直径的能力值的骑士去杀。
#include <iostream>#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>#include <vector>#include <map>using namespace std;const int MAX = 20005;int n, m;int dragon[MAX], knight[MAX];void input(){ for(int i = 0; i < n; i++) scanf("%d", &dragon[i]); for(int i = 0; i < m; i++) scanf("%d", &knight[i]);}void solve(){ sort(dragon, dragon + n); sort(knight, knight + m); int j = 0; int ans = 0; for(int i = 0; i < n; i++) { while(j < m && knight[j] < dragon[i]) j++; if(j == m) { printf("Loowater is doomed!\n"); return; } ans += knight[j]; j++; } printf("%d\n", ans);}int main(){ while(scanf("%d%d", &n, &m) && !(n == 0 && m == 0)) { input(); solve(); } return 0;}
0 0
- 勇者斗恶龙(The Dragon of Loowater) UVa 11292 HDU 1902
- 勇者斗恶龙(The Dragon of Loowater, UVa 11292)
- UVa 11292 The Dragon of Loowater 勇者斗恶龙
- uva 11292 勇者斗恶龙 The Dragon of Loowater
- 勇者斗恶龙(The Dragon of Loowater, UVa 11292)
- UVA 11292(Dragon of Loowater-勇者斗恶龙)
- 勇者斗恶龙(The Dragon Loowater,UVA 11292)
- The Dragon of Loowater(勇者斗恶龙)
- uva 11292 Dragon of Loowater (勇者斗恶龙)
- uva 11292 Dragon of Loowater (勇者斗恶龙系列)
- 例题5-1 UVA 11292 The Dragon of Loowater勇者斗恶龙
- 11292 - Dragon of Loowater 勇者斗恶龙
- UVa 11292 - The Dragon of Loowater
- UVa 11292 The Dragon of Loowater
- UVA 11292 - The Dragon of Loowater (water)
- uva 11292 The Dragon of Loowater
- UVA 11292 The Dragon of Loowater
- uva 11292The Dragon of Loowater
- solr 4.7.2 环境搭建
- 模式识别入门与贝叶斯决策理论
- 【LeetCode #179】Largest Number 解题报告
- 浅谈Autolayout之Masonry
- Android一分钟环境搭建,包含Mac、Linux、Windows
- UVa 11292 The Dragon of Loowater 勇者斗恶龙
- valgrind跟踪fork出的子进程-debug调试
- 解决安卓点击图片跳转时候的蓝色边框问题
- sap 去掉小数位没用的0
- uva 1103 详解
- NSString截取字符串
- JFreeChart 2
- TreeView 快速单击时不执行AfterCheck时间
- [C#] 调试silverlight的时候,总是报“向占位程序传送了空的索引指针”