UVa 11292 勇者斗恶龙
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 勇者斗恶龙的更多相关文章
- UVa 11292 勇者斗恶龙(The Dragon of Loowater)
首先先看一下这道题的英文原版... 好吧,没看懂... 大体意思就是: 有一条n个头的恶龙,现在有m个骑士可以雇佣去杀死他,一个能力值为x的勇士可以砍掉直径不超过x的头,而且需要支付x个金币.如何雇佣 ...
- 算法 UVA 11292
***从今天开始自学算法. ***代码是用c++,所以顺便再自学一下c++ 例题1 勇者斗恶龙(The Dragon of Loowater, UVa 11292) 你的王国里有一条n个头的恶龙,你 ...
- 贪心/思维题 UVA 11292 The Dragon of Loowater
题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...
- cogs 1405. 中古世界的恶龙[The Drangon of Loowater,UVa 11292]
1405. 中古世界的恶龙[The Drangon of Loowater,UVa 11292] ★ 输入文件:DragonUVa.in 输出文件:DragonUVa.out 简单对比时间 ...
- UVa 11292 The Dragon of Loowater 勇者斗恶龙
你的王国里有一条n个头的恶龙,你希望雇佣一些骑士把它杀死(也就是砍掉所有的头).村里有m个骑士可以雇佣,一个能力值为 x 的骑士可以砍掉恶龙一个直径不超过 x 的头,且需要支付 x 个金币.如何雇佣骑 ...
- uva 11292 Dragon of Loowater (勇者斗恶龙)
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- 勇者斗恶龙 uva 11292(简单贪心)
思路:先将龙和士兵进行分别排序从小到大.然后,每次找当前最小龙的第一个大于它的骑手之后退出,开始下一个龙,重复上一次操作. #include<iostream> #include<a ...
- 勇者斗恶龙 UVA 11292
Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shor ...
- UVA 11292 Dragon of Loowater(简单贪心)
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
随机推荐
- csv文件的读写
# -*- coding: utf-8 -*- """ Spyder Editor This is a temporary script file. "&quo ...
- SVN出现xcrun: error: invalid active developer path(Mac)
Mac升级了系统,配置PHPStorm的SVN,出现如下错误: 具体提示的内容是:xcrun: error: invalid active developer path (/Library/Devel ...
- python3中pymysql模块安装及连接数据库(同‘python安装HTMLTestRunner’)
https://pypi.org/project/PyMySQL/#files 安装完成之后就是连接数据库了 机器上安装了mysql的数据库,并且已经创建了两张表用于测试 python3连接数据库及删 ...
- L1正则化和L2正则化
L1正则化可以产生稀疏权值矩阵,即产生一个稀疏模型,可以用于特征选择 L2正则化可以防止模型过拟合(overfitting):一定程度上,L1也可以防止过拟合 一.L1正则化 1.L1正则化 需注意, ...
- GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.2/gradle-3
Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.2/gradle-3 ...
- 转载如何实现portlet之间的传递参数
Liferay 6开发学习(三十):跨页面Portlet之间的调用与数据传递 2014年10月09日 Liferay 评论 2 条 阅读 4,209 views 次 Portlet之间的通信方法有多种 ...
- 转载 vsftpd安装
http://blog.csdn.net/shutfuckingup/article/details/8250290 1:安装vsftpd yum install vsftpd 2:关闭防火墙 ...
- discuz模板引擎
discuz是采用“编译型的模板”,就是指采用普通网页文件保存,在文件中插入需要动态显示数据的仿php的代码,最后进行编译成真正的php的文件保存为模板缓存文件,这个转换的过程就称为编译.在用户浏览页 ...
- kendo datetimepicker
@(Html.Kendo().DatePicker() .Name("yearCalendar") .Value(DateTime.Now) .Start(CalendarView ...
- 【tensorflow】pip 安装失败的原因
linux系统旧版本: pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27- ...