UVA 11292-Dragon of Loowater (贪心)
Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem.
The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predators, the geese population was out of control. The people of Loowater mostly kept clear of the geese. Occasionally, a goose would attack one of the people, and perhaps bite off a finger or two, but in general, the people tolerated the geese as a minor nuisance.
One day, a freak mutation occurred, and one of the geese spawned a multi-headed fire-breathing dragon. When the dragon grew up, he threatened to burn the Kingdom of Loowater to a crisp. Loowater had a major problem. The king was alarmed, and called on his knights to slay the dragon and save the kingdom.
The knights explained: "To slay the dragon, we must chop off all its heads. Each knight can chop off one of the dragon's heads. The heads of the dragon are of different sizes. In order to chop off a head, a knight must be at least as tall as the diameter of the head. The knights' union demands that for chopping off a head, a knight must be paid a wage equal to one gold coin for each centimetre of the knight's height."
Would there be enough knights to defeat the dragon? The king called on his advisors to help him decide how many and which knights to hire. After having lost a lot of money building Mir Park, the king wanted to minimize the expense of slaying the dragon. As one of the advisors, your job was to help the king. You took it very seriously: if you failed, you and the whole kingdom would be burnt to a crisp!
Input Specification:
The input contains several test cases. The first line of each test case contains two integers between 1 and 20000 inclusive, indicating the number n of heads that the dragon has, and the number m of knights in the kingdom. The next n lines each contain an integer, and give the diameters of the dragon's heads, in centimetres. The following mlines each contain an integer, and specify the heights of the knights of Loowater, also in centimetres.
The last test case is followed by a line containing:
0 0
Output Specification:
For each test case, output a line containing the minimum number of gold coins that the king needs to pay to slay the dragon. If it is not possible for the knights of Loowater to slay the dragon, output the line:
Loowater is doomed!
Sample Input:
2 3
5
4
7
8
4
2 1
5
5
10
0 0
Output for Sample Input:
11
Loowater is doomed!
题解:贪心
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main() {
int n,m;
int a[100005];
int b[100005];
while(scanf("%d%d",&n,&m)!=EOF) {
if(n==0&&m==0) {
break;
}
for(int t=0; t<n; t++) {
scanf("%d",&a[t]);
}
for(int t=0; t<m; t++) {
scanf("%d",&b[t]);
}
sort(a,a+n);
sort(b,b+m);
long long int sum=0;
int j=0;
for(int t=0; t<m; t++) {
if(a[j]<=b[t]) {
sum+=b[t];
j++;
if(j==n) {
break;
}
}
}
if(j<n) {
printf("Loowater is doomed!\n");
} else {
printf("%lld\n",sum);
}
}
return 0;
}
UVA 11292-Dragon of Loowater (贪心)的更多相关文章
- 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 ...
- [ACM_水题] UVA 11292 Dragon of Loowater [勇士斗恶龙 双数组排序 贪心]
Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shor ...
- UVa 11292 - Dragon of Loowater(排序贪心)
Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem.The shore ...
- UVa 11292 Dragon of Loowater
简单贪心 龙头的直径和人的佣金排序,价值小的人和直径小的配 #include<iostream> #include<cstdio> #include<cmath> ...
- UVa 11292 Dragon of Loowater (水题,排序)
题意:有n个条龙,在雇佣勇士去杀,每个勇士能力值为x,只能杀死头的直径y小于或等于自己能力值的龙,只能被雇佣一次,并且你要给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 The Dragon of Loowater(贪心)
题目大意: 你的王国里有一条n个头的恶龙,你希望雇一些骑士把它杀死(即砍掉所有头).村里有m个骑士可以雇佣,一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x个金币.如何雇佣骑士才 ...
- 贪心/思维题 UVA 11292 The Dragon of Loowater
题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...
随机推荐
- "点"醒自己
回顾: 过去的经历 从18年开始在某机构进行了测试培训,9月正式加入测试小白大军,中间也经历了半年的空窗期,入职2个月应能力不够被公司辞退,后通过培训班的朋友内推到一家软件外包公司,工作到现在. 思考 ...
- python4.1定义函数
def add(a,b,c,d): e=a+b+c-d return e result=add(21,32,43,56)print("加和结果是:",result) def zzj ...
- 极简 Node.js 入门 - 1.2 模块系统
极简 Node.js 入门系列教程:https://www.yuque.com/sunluyong/node 本文更佳阅读体验:https://www.yuque.com/sunluyong/node ...
- 006_go语言中的互斥锁的作用练习与思考
在go语言基本知识点中,我练习了一下互斥锁,感觉还是有点懵逼状,接下来为了弄懂,我再次进行了一些尝试,以下就是经过我的尝试后得出的互斥锁的作用. 首先还是奉上我改造后的代码: package main ...
- Java基础高级篇 NIO
nio模型与io模型的对比 netty 是什么 怎么使用
- Docker 启动 OpenResty
Docker 启动 OpenResty OpenResty 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库.第三方模块以及大多数的依赖项.用于方便地搭建 ...
- 9个常用ES6特性归纳(一般用这些就够了)
ECMAScript 6.0(以下简称 ES6)是 JavaScript 语言的下一代标准,已经在 2015 年 6 月正式发布了.它的目标,是使得 JavaScript 语言可以用来编写复杂的大型应 ...
- [Kong 与 Konga与postgres数据库] 之 Kuberneres 部署
1.Kong的概述 Kong是一个clould-native.快速的.可扩展的.分布式的微服务抽象层(也称为API网关.API中间件或在某些情况下称为服务网格)框架.Kong作为开源项目在2015年推 ...
- Linux中su和su -区别,别再傻傻分不清
写在前面 如果你不清楚su和su -切换用户的区别,你一定会遇到在使用su切换用户执行命令出现报错"command not found"感到惊讶.分明之前这个指令执行的好好的,为什 ...
- C++ Templates (1.4 默认模板实参 Default Template Arguments)
返回完整目录 目录 1.4 默认模板实参 Default Template Arguments 1.4 默认模板实参 Default Template Arguments 可以为模板参数定义默认值,这 ...