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 简单对比时间 ...
随机推荐
- mvc cshtml 中赋值
@{ var str = ""; str = item.ApplyStatus == ? ? ? ? "申请驳回" : ""; } < ...
- Java中方法重载
方法重载:指在同一个类中,允许存在一个以上的同名方法,只要它们的参数列表不同即可,与修饰符和返回值类型无关. 参数列表:个数不同,数据类型不同,顺序不同. 重载方法调用:JVM通过方法的参数列表,调用 ...
- 推荐一款能支持国密SM2浏览器——密信浏览器
密信浏览器( MeSince Browser )是基于Chromium开源项目开发的国密安全浏览器,支持国密算法和国密SSL证书,同时也支持国际算法及全球信任SSL证书:密信浏览器使用界面清新,干净. ...
- centos7.XXX配置python3环境
众做周知,centos 是自带python2.7的.可是随着社会的进步,科技的发展,技术一步步更新换代,python2.7已经不足以满足项目的需求.这时候python3横空出世. 下面跟着我来一起实现 ...
- Zookeeper 使用
转自:https://www.ibm.com/developerworks/cn/opensource/os-cn-zookeeper/ 安装和配置详解 本文介绍的 Zookeeper 是以 3.2. ...
- 记Spring搭建功能完整的个人博客「Oyster」全过程[其二] Idea中Maven+SpringBoot多模块项目开发的设计和各种坑(模块间依赖和打包问题)
大家好嘞,今天闲着没事干开写写博客,记录一下Maven+SpringBoot的多模块设计和遇到的坑. 多模块设计 简单说明一下截止目前的需求: 需要RESTful API:对文章.标签.分类和评论等的 ...
- 小松之LINUX 驱动学习笔记(开篇)
时间对每个人都是公平的,就看你怎么对待他.每天多努力一点,未来就会轻松一点.作为一名北漂,感受着首都的压力,也曾萌生过逃离北上广的想法,但是,最后我最终还是选择留下来,随着年龄的增长,我已经没有那么多 ...
- [剑指offer] 50. 第一个只出现一次的字符 + map,hashmap 及其区别
class Solution { public: int FirstNotRepeatingChar(string str) { map<char,int>mp; ;i<str.si ...
- Updates were rejected because the remote contains work that you do(gitee报错解决方案)
今天向Gitee远程仓库提交本地项目文件时,遇到了下列错误,很是郁闷 正在推送 1203笔记本Error: failed to push some refs to 'https://gitee.com ...
- FreeMarker 页面静态化解决方案
一.网页的静态化方案 1.生成静态页面的时机:在做添加操作时,同时生成该新增内容的对应的静态页面 2.静态页面的名称:内容 id + ".html" 3.静态页面所在的路径:工程外 ...