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. Centon6.5虚拟机桥接设置

    参考资料:http://blog.csdn.net/iamfafa/article/details/6209009 安装虚拟机的时候 就直接选择桥接,可以直接 使用 查看此状态下的配置如下 : 虚拟环 ...

  2. python实现单向链表

    #Definition for singly-linked list. class ListNode(object): def __init__(self, x): self.val = x self ...

  3. BZOJ 1684: [Usaco2005 Oct]Close Encounter

    题目 1684: [Usaco2005 Oct]Close Encounter Time Limit: 5 Sec  Memory Limit: 64 MB Description Lacking e ...

  4. 包子IT面试培训

    包子IT面试培训 IT 面试不再怕,包子帮你圆个梦!

  5. UIColor深入研究(CGColor,CIColor)

    由于跟人比较喜欢研究关于图层与动画方面的技术,正打算看看别人写的好东西,就遇到了好几个问题, 第一:UIClor类方法的使用 就是关于UIColor的使用,记得之前开发中我们使用的都是UIColor后 ...

  6. [Swust OJ 85]--单向公路(BFS)

    题目链接:http://acm.swust.edu.cn/problem/0085/ Time limit(ms): 5000 Memory limit(kb): 65535   Descriptio ...

  7. java多线程监听JMS、MQ队列

    本作品采用知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议进行许可. 转载请注明出处和作者.http://blog.csdn.net/xtj332 背景:消息队列中有非常多的消息需要 ...

  8. 循环调用修正sic86 2改后的(除了第一年有点诡异,其他年份可以正常修复)

    create or replace procedure rebuild_sic86_wyl(pi_aac001 in number, po_fhz out varchar2, po_msg out v ...

  9. HDU 1004 MAP【STL__map_的应用】

    强大的MAP,今天终于开始好好学习一次. map内部是用红黑树维持的有序结构. 定义:map<int,string>mapStudent; 查找的时间复杂度为对数级别. 1.构造方法学习两 ...

  10. git常用命令2

    一. Git 常用命令速查 git branch 查看本地所有分支git status 查看当前状态 git commit 提交 git branch -a 查看所有的分支git branch -r ...