UVa 11292 The Dragon of Loowater 【贪心】
题意:有一条有n个头的恶龙,有m个骑士去砍掉它们的头,每个骑士可以砍直径不超过x的头,问怎样雇佣骑士,使花的钱最少
把头的直径从小到大排序,骑士的能力值也从小到大排序,再一个一个地去砍头
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int a[maxn],b[maxn];
int n,m; int main(){
while(scanf("%d %d",&n,&m) != EOF && n && m){
memset(a,,sizeof(a));
memset(b,,sizeof(b));
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=m;i++) scanf("%d",&b[i]);
sort(a+,a+n+);
sort(b+,b+m+); int ans = ;
int cnt = ;
for(int i=;i<=m;i++){
if(b[i] >= a[cnt]) ans += b[i],cnt++;
if(cnt == n+ ) break;
}
if(cnt <= n) printf("Loowater is doomed!\n");
else printf("%d\n",ans);
}
return ;
}
UVa 11292 The Dragon of Loowater 【贪心】的更多相关文章
- uva 11292 The Dragon of Loowater(贪心)
题目大意: 你的王国里有一条n个头的恶龙,你希望雇一些骑士把它杀死(即砍掉所有头).村里有m个骑士可以雇佣,一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x个金币.如何雇佣骑士才 ...
- 贪心/思维题 UVA 11292 The Dragon of Loowater
题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...
- UVa 11292 The Dragon of Loowater 勇者斗恶龙
你的王国里有一条n个头的恶龙,你希望雇佣一些骑士把它杀死(也就是砍掉所有的头).村里有m个骑士可以雇佣,一个能力值为 x 的骑士可以砍掉恶龙一个直径不超过 x 的头,且需要支付 x 个金币.如何雇佣骑 ...
- UVA 11292 - The Dragon of Loowater (water)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=sh ...
- UVA - 11292 Dragon of Loowater 贪心
贪心策略:一个直径为X的头颅,应该让雇佣费用满足大于等于X且最小的骑士来砍掉,这样才能使得花费最少. AC代码 #include <cstdio> #include <cmath&g ...
- 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 - Dragon of Loowater
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- uva 11292 Dragon of Loowater (勇者斗恶龙)
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- cogs 1405. 中古世界的恶龙[The Drangon of Loowater,UVa 11292]
1405. 中古世界的恶龙[The Drangon of Loowater,UVa 11292] ★ 输入文件:DragonUVa.in 输出文件:DragonUVa.out 简单对比时间 ...
随机推荐
- WebStorm 配置 svn
1.下载 SlikSVN. 2.安装.路径 D:\Program Files\slik\bin. 3.在WebStorm中配置 file->settings->Version Co ...
- 使用js控制文本超出部分显示省略号
js代码 // 字数限制30字,超出不显示 fontNumber (date) { const length = date.length if (length > 30) { var str = ...
- kali 安装nessus
下载home版: http://www.tenable.com/products/nessus/select-your-operating-system#tos 获取激活码:http://www.te ...
- NYOJ-1013除法表达式
除法表达式 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 给出一个这样的除法表达式:X1/X2/X3/···/Xk,其中Xi是正整数.除法表达式应当按照从左到右的顺 ...
- Java包名称中通配符的含义
"com.abc 表示的意义为:系统从com.abc这个包及其子孙包扫描组件 "com.abc.* 表示的意义为:系统从com.abc这个包的子孙包扫描组件
- 树状数组求LIS
我真的是咸鱼啊 多少年前的基础了我竟然才弄明白,哭 用树状数组维护<=x的最上上升子序列的最大值即可啊Orz 我真的菜的一笔啊! #include <bits/stdc++.h> u ...
- JAVA 中 重定向
一.重定向:一个web资源收到客户端的请求后,通知客户端去访问另外一个web资源,这称之为请求重定向. 运用场景:如用户登录. 实现方式:通过response来实现: 如: 1.response.se ...
- Problem 11
Problem 11 # Problem_11.py """ In the 20×20 grid below, four numbers along a diagonal ...
- matlab经验总结(转)
Matlab使用的一点儿体会(For Beginner) 作者:Genial(山城棒棒儿军) 转自 不明 真正接触matlab一年左右,我很喜欢上了matlab的简单的语法,易于绘制图形,gui ...
- Strtus配置Tomcat出现问题
在使用 eclipse 过程中,如果你加入了某些自定义的框架(比如 struts)后,在启动 services 后, 控制台出现一片红色的字样,表明有问题.这时仔细查看 eclipse 控制台信息, ...