UVA - 11292 Dragon of Loowater (贪心)
2015-02-23 19:58
405 查看
题目大意:有n条龙和m个勇士,每条龙和每个勇士有对应的能力值,消灭一条龙的条件是这个勇士的能力大于等于这条龙,请一个勇士要付出其能力值大小的金币,现要求将所有的龙的消灭并使所使用的金币达到最小
解题思路:将龙的能力和勇士的能力都排序一下.
因为要让金币达到最小且要消灭所有的龙,所以尽量用能力值最接近勇士去消灭龙
解题思路:将龙的能力和勇士的能力都排序一下.
因为要让金币达到最小且要消灭所有的龙,所以尽量用能力值最接近勇士去消灭龙
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define maxn 20010 int D[maxn], K[maxn]; int main() { int n, m; while(scanf("%d%d",&n ,&m) == 2 && n + m) { for(int i = 0; i < n; i++) scanf("%d",&D[i]); for(int j = 0; j < m; j++) scanf("%d",&K[j]); sort(D,D+n); sort(K,K+m); int start = 0, money = 0; for(int i = 0; i < m; i++) { if(K[i] >= D[start]) { money += K[i]; start++; } if(start >= n) break; } if(start < n) printf("Loowater is doomed!\n"); else printf("%d\n",money); } return 0; }
相关文章推荐
- uva11292 - The Dragon of Loowater (贪心)
- UVA 11292 Dragon of Loowater(简单贪心)
- JAVA-勇者斗恶龙-The Dragon of Loowater,Uva 11292-排序后贪心
- uva11292 The Dragon of Loowater (排序+贪心)
- UVa 11292 / POJ 3646 / HDU 1902 Dragon of Loowater (贪心)
- UVA 11292 Dragon of Loowater(贪心)
- UVa - 11292 - Dragon of Loowater ( 排序 + 贪心 )
- |UVA 11292|贪心|Dragon of Loowater
- Uva11292--------------(The Dragon of Loowater)勇者斗恶龙 (排序后贪心)
- UVA.11292 Dragon of Loowater (贪心)
- UVA 11292 Dragon of Loowater 贪心 .
- UVa11292 - Dragon of Loowater (贪心+模拟)
- Uva---11292Problem C: The Dragon of Loowater (贪心)
- UVa-11292 Dragon of Loowater (贪心)
- uva11292 The Dragon of Loowater (排序+贪心)
- UVa11292 - Dragon of Loowater(贪心)
- uva 11292 - Dragon of Loowater(贪心)
- UVa 11292 - Dragon of Loowater(贪心)
- UVa 11292 Dragon of Loowater 贪心+排序
- UVA 11292 DRAGON OF LOOWATER 【贪心】