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 ...
随机推荐
- golang语言中的context详解,Go Concurrency Patterns: Context
https://blog.golang.org/context Introduction In Go servers, each incoming request is handled in its ...
- [py][mx]operation模型设计
用户表 UserMesasage 用户消息 UserFavorite 用户收藏 UserAsk 用户咨询 UserCourse 用户学习的课程 CourseComments 用户评论 收藏有3种类型 ...
- plsql的sql窗口中文模糊查询没有作用
环境变量新增: NLS_LANG = AMERICAN_AMERICA.AL32UTF8
- NLP语料库
文本语料库是一个大型结构化文本的集合 NLTK包含了许多语料库: (1)古滕堡语料库 (2)网络和聊天文本 (3)布朗语料库 (4)路透社语料库 (5)就职演讲语料库 (6)标注文本语料库 词汇列表 ...
- 1.0ARM体系结构-ARM体系结构
对ARMcpu有整体而专业的认识. ARM只是设计arm核,而不生产. ARM 掌握的是标准.
- qt mysql驱动问题解绝
传统解决方法:一.解决问题 本文解决在Ubuntu16.04系统下,Qt5无法连接MySQL数据库的问题(Qt5缺少MySQL驱动,Qt5缺少libqsqlmysql.so动态库,如何安装libqsq ...
- discuz $_G变量
class.core.php中 global $_G; $_G = array( 'uid' => 0, 'username' => ...
- 172. Factorial Trailing Zeroes(阶乘中0的个数 数学题)
Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 Explan ...
- kail linux nmap命令
可用于: 检测活在网络上的主机(主机发现)检测主机上开放的端口(端口发现或枚举)检测到相应的端口(服务发现)的软件和版本检测操作系统,硬件地址,以及软件版本检测脆弱性的漏洞(Nmap的脚本) ---- ...
- input hidden的作用
网上辣么多blabla的,我就总结一下 1 什么是hidden hidden 是input type的一个值,叫隐藏域,官方解释:“Hidden 对象代表一个 HTML 表单中的某个隐藏输入域. 这种 ...