http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2267

题目大意:n条恶龙,m个勇士,用勇士来杀恶龙。一个勇士只能杀一个恶龙。而且勇士只能杀直径不超过自己能力值的恶龙。每个勇士需要支付能力值一样的金币。问杀掉所有恶龙需要的最少金币?


题意分析:先排序,再进行筛选。

#include<stdio.h>
#include<algorithm> // sort
#include<iostream>
#include<string.h>
using namespace std;
const int MAXN=20010;
int A[MAXN],B[MAXN];
int main()
{
int n,m;
int i,j;
while(scanf("%d%d",&n,&m)==2 && n && m)
{
for(i=0;i<n;i++)scanf("%d",&A[i]);
for(i=0;i<m;i++)scanf("%d",&B[i]);
sort(A,A+n);
sort(B,B+m);
i=0;
j=0;
int ans=0;
for(i=0;i<n;i++)
{
if(j>=m)break;
while(j<m && A[i]>B[j])j++;
if(j>=m)break;
ans+=B[j];
j++;
}
if(i < n) printf("Loowater is doomed!\n");
else printf("%d\n",ans);
}
return 0;
}

UVA 11292 - The Dragon of Loowater (water)的更多相关文章

  1. 贪心/思维题 UVA 11292 The Dragon of Loowater

    题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...

  2. UVa 11292 The Dragon of Loowater 勇者斗恶龙

    你的王国里有一条n个头的恶龙,你希望雇佣一些骑士把它杀死(也就是砍掉所有的头).村里有m个骑士可以雇佣,一个能力值为 x 的骑士可以砍掉恶龙一个直径不超过 x 的头,且需要支付 x 个金币.如何雇佣骑 ...

  3. uva 11292 The Dragon of Loowater(贪心)

    题目大意:   你的王国里有一条n个头的恶龙,你希望雇一些骑士把它杀死(即砍掉所有头).村里有m个骑士可以雇佣,一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x个金币.如何雇佣骑士才 ...

  4. UVa 11292 The Dragon of Loowater 【贪心】

    题意:有一条有n个头的恶龙,有m个骑士去砍掉它们的头,每个骑士可以砍直径不超过x的头,问怎样雇佣骑士,使花的钱最少 把头的直径从小到大排序,骑士的能力值也从小到大排序,再一个一个地去砍头 #inclu ...

  5. UVA它11292 - Dragon of Loowater

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  6. UVA 11292 Dragon of Loowater(简单贪心)

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  7. uva 11292 Dragon of Loowater (勇者斗恶龙)

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  8. cogs 1405. 中古世界的恶龙[The Drangon of Loowater,UVa 11292]

    1405. 中古世界的恶龙[The Drangon of Loowater,UVa 11292] ★   输入文件:DragonUVa.in   输出文件:DragonUVa.out   简单对比时间 ...

  9. 算法 UVA 11292

    ***从今天开始自学算法. ***代码是用c++,所以顺便再自学一下c++ 例题1  勇者斗恶龙(The Dragon of Loowater, UVa 11292) 你的王国里有一条n个头的恶龙,你 ...

随机推荐

  1. Yii2归档安装法

    打开dos 操作命令  1.先把init.bat  拖到dos命令窗口 打开 (如果拖过去没打开 可以回车Enter一下) 这里需要注意一下  下图红圈中是两种环境  0->开发环境  1-&g ...

  2. beta分布

    http://blog.csdn.net/sweetrryy/article/details/6436358

  3. CMD获取当前目录的绝对路径

    @echo offecho 当前盘符:%~d0echo 当前盘符和路径:%~dp0echo 当前批处理全路径:%~f0echo 当前盘符和路径的短文件名格式:%~sdp0echo 当前CMD默认目录: ...

  4. 挺有意思的HBase日志+Splunk

    如题,转载自: http://hi.baidu.com/harry_lime/item/10cf2c174853c7ea39cb3042 如何模拟拔盘操作 Linux has a nifty way ...

  5. 统计单词频率--map

    问题描述: 输入一个单词列表,每行一个单词,统计单词出现的频率 思路: 主要是使用c++中的map容器.map实质上是一个二叉查找树,可以做到插入.删除.查询,平均查询时间在O(logn).n为map ...

  6. IOS 时间格式 时间转换 大总结

    //实例化一个NSDateFormatter对象 NSDateFormatter *dateFormatter = [[NSDateFormatteralloc] init]; //设定时间格式,这里 ...

  7. ThreadLocal 和 InheritableThreadLocal (引用)

    ThreadLocal:http://www.cnblogs.com/moonandstar08/p/4912673.html InheritableThreadLocal:  http://www. ...

  8. Android:OptionMenu

    MainActivity: package com.example.optionmenu; import android.content.Intent; import android.os.Bundl ...

  9. (Problem 14)Longest Collatz sequence

    The following iterative sequence is defined for the set of positive integers: n n/2 (n is even) n 3n ...

  10. 使用ARC必须遵守的规则

    l        不可以再显示调用dealloc.或实现调用retain.release.retainCount.autorelease这些方法.也不能使用@selector(retain), @se ...