【题解】 UVa11292 The Dragon of Loowater
题目大意:
你的王国里有一条n个头的恶龙,你希望雇佣一些骑士把它杀死(即砍掉所有头)。村里有m个骑士可以雇佣,一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x个金币。如何雇佣骑士才能砍掉龙的所有头,且需要支付的金币最少?注意,一个骑士只能砍一个头。(且不能被雇佣两次)。 输入格式
输入包含多组数据。每组数据的第一行为正整数n和m(1<=n,m<=20000);以下n行每行为一个整数,即恶龙每个头的直径;以下m行每行为一个整数,即每个骑士的能力。输入结束标志为n=m=0。 输出格式
对于每组数据,输出最小花费。如果无解,输出“Loowater is doomed!”。
Solution
显然我们要让勇士砍最适合他的龙,所以就考虑直接排序+贪心就好了...
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<queue>
#define ll long long
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
using namespace std;
inline int gi(){
int sum=0,f=1;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')f=-f;ch=getchar();}
while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
return f*sum;
}
inline ll gl(){
ll sum=0,f=1;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')f=-f;ch=getchar();}
while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
return f*sum;
}
const int N=20010;
int a[N],b[N];
int main(){
int i,j,n,m,k;
while(scanf("%d%d",&n,&m)==2 && n && m){
for(i=1;i<=n;i++)a[i]=gi();
for(i=1;i<=m;i++)b[i]=gi();
sort(a+1,a+n+1);sort(b+1,b+m+1);
int t=1;ll ans=0;
for(i=1;i<=m && t<=n;i++){
if(a[t]>b[i])continue;
ans+=b[i];t++;
}
if(t>n)printf("%lld\n",ans);
else puts("Loowater is doomed!");
}
return 0;
}
【题解】 UVa11292 The Dragon of Loowater的更多相关文章
- uva-----11292 The Dragon of Loowater
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- The Dragon of Loowater
The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into ...
- 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 ...
- Dragon of Loowater
option=com_onlinejudge&Itemid=8&page=show_problem&problem=2267" style="color:b ...
- 贪心/思维题 UVA 11292 The Dragon of Loowater
题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...
- 勇者斗恶龙UVa11292 - Dragon of Loowater
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=s ...
- uva11292 Dragon of Loowater
水题,排序遍历即可 #include<iostream> #include<cstdio> #include<algorithm> using namespace ...
随机推荐
- js keyup、keypress和keydown事件 详解
js keyup.keypress和keydown事件 详解 js keyup.keypress和keydown事件都是有关于键盘的事件 当一个按键被pressed 或released在每一个现代浏 ...
- 根文件系统的构建与分析(三)之根文件目录及最简/dev目录
根文件系统的构建与分析(三) 转载请注明 http://blog.csdn.net/jianchi88 Author:Lotte 邮箱:baihaowen08@126.com 一.FHS(Fi ...
- 第九章 整合Mybatis(待续)
··········
- C过程思想,根据需求写方法就行
实现的方法有多种 Comprehensive orientate 2017/10/27 13:25:07 C过程思想,根据需求写方法就行
- springboot整合redis单机及集群
一.单机配置 properties配置 #单机redis spring.redis.host=127.0.0.1 spring.redis.port=6379 spring.redis.passwor ...
- Java虚拟机(四):常用JVM配置参数
一.VM选项 - : 标准VM选项,VM规范的选项 -X: 非标准VM选项,不保证所有VM支持 -XX: 高级选项,高级特性,但属于不稳定的选项 参见Java HotSpot VM Options 二 ...
- Express的路由详解
Express的路由详解 http://www.jb51.net/article/76203.htm
- Leetcode:Two Sum分析和实现
问题表示提供一个整数数组nums,以及一个目标target,要找到两个下标i与j,使得nums[i] + nums[j] = target. 最简单的思路是两次循环: for a in nums fo ...
- vector向量容器
vector向量容器不但可以像数组一样对元素进行随机访问,还能在尾部插入元素,是一种简单高效的容器,可以代替数组. vector具有内存自动管理的功能,对于元素的插入和删除,可以动态的调整所占内存. ...
- 什么是Kali Linux?
什么是Kali Linux? Kali Linux是一个基于Debian的Linux发行版,旨在实现高级渗透测试和安全审计.Kali包含数百种工具,适用于各种信息安全任务,如渗透测试,安全研究,计算机 ...