https://vjudge.net/problem/UVA-11292

题意:
有n条任意个头的恶龙,你希望雇一些其实把它杀死。一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x个金币。输出最少金币。

思路:

对两者进行排序。依次比较,头少的龙尽量用能力值小的骑士去砍。

 #include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std; const int maxn = + ; int n, m;
int a[maxn], b[maxn]; int main()
{
//freopen("D:\\txt.txt", "r", stdin);
while (cin >> n >> m)
{
if (!n&&!m) break;
for (int i = ; i < n; i++)
cin >> a[i];
for (int i = ; i < m; i++)
cin >> b[i];
sort(a, a + n);
sort(b, b + m);
int p1 = , p2 = ;
int sum = ;
while (p1 < n && p2 < m)
{
if (b[p2]>=a[p1])
{
sum += b[p2];
p1++;
p2++;
}
else p2++;
}
if (p1 < n) cout << "Loowater is doomed!" << endl;
else cout << sum << endl;
}
}

UVa 11292 勇者斗恶龙的更多相关文章

  1. UVa 11292 勇者斗恶龙(The Dragon of Loowater)

    首先先看一下这道题的英文原版... 好吧,没看懂... 大体意思就是: 有一条n个头的恶龙,现在有m个骑士可以雇佣去杀死他,一个能力值为x的勇士可以砍掉直径不超过x的头,而且需要支付x个金币.如何雇佣 ...

  2. 算法 UVA 11292

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

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

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

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

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

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

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

  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(简单贪心)

    思路:先将龙和士兵进行分别排序从小到大.然后,每次找当前最小龙的第一个大于它的骑手之后退出,开始下一个龙,重复上一次操作. #include<iostream> #include<a ...

  8. 勇者斗恶龙 UVA 11292

    Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shor ...

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

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

随机推荐

  1. resume 简历

    1:uestc社会实践平台,sql,mapper.xml,,图片验证码,读写excel,excel和list,数据库的转化. 2:购物网站,全代码,平台搭建,服务发布,远程数据库连接,前端,搜索,支付 ...

  2. quic协议实时视频直播

    扫盲 https://www.jianshu.com/p/b7546ff9b683 demo https://github.com/felix-001/QuicRtmp https://github. ...

  3. 使用webpy创建一个简单的restful风格的webservice应用

    下载:wget http://webpy.org/static/web.py-0.38.tar.gz解压并进入web.py-0.38文件夹安装:easy_install web.py 这是一个如何使用 ...

  4. MongoDB和pymongo自用手册

    [*] 本文出处:http://b1u3buf4.xyz/ [*] 本文作者:B1u3Buf4 [*] 本文授权:禁止转载 从自己的另一处博客移动过来.长期维护,不定期添加新内容. 前述和安装 mon ...

  5. [LeetCode] 438. Find All Anagrams in a String_Easy

    438. Find All Anagrams in a String DescriptionHintsSubmissionsDiscussSolution   Pick One Given a str ...

  6. testNG入门详解

    TestNG 的注释: @DataProvider @ExpectedExceptions @Factory @Test @Parameters <suite name="Parame ...

  7. RVDS编译器

    不同ARM的体系结构,使用的ARM RealView编译工具时的异同点. 1)ARM体系结构v6K首次引入对4个CPU的MPCore处理器支持,高效的多重处理系统与单CPU系统相比,功耗更低,散热量更 ...

  8. ARM中的汇编指令

    Arm指令,32位的指令集,一共有16条的基本指令,每条指令都可以按条件执行, 指令都是32bit的,高四位是条件码[31:28], Thumb指令,16位的指令集,执行效率比arm指令集要低,但是节 ...

  9. Lower Power with CPF(二)

    CPF文件可以有两种组织方式:Flat CPF file or Hierarchical CPF file. 由于在大型的SoC设计中,一般都采用Hierarchical的形式,所以本文主要按这个方式 ...

  10. 18B树、B++树和Trie树

    B树.B++树和Trie树 B树 定义:一个非空M元(也称M阶)B树(R.Bayer,1970年) 满足下列条件: 1)每个结点含有m个元素a1<a2<…<am.含有m个元素的结点有 ...