UVa 11292 Dragon of Loowater (水题,排序)
题意:有n个条龙,在雇佣勇士去杀,每个勇士能力值为x,只能杀死头的直径y小于或等于自己能力值的龙,只能被雇佣一次,并且你要给x赏金,求最少的赏金。
析:很简单么,很明显,能力值高的杀直径大的,低的杀直径小的。所以我们先对勇士能力值从小到大排序,然后对龙的直径从小到大排序,
然后扫一遍即可,如某个勇士杀不龙,就可以跳过,扫到最后,如果杀完了就结束,输出费用,否则就是杀不完。
代码如下:
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <map> using namespace std;
const int maxn = 20000 + 10; int a[maxn], b[maxn]; int main(){
int n, m;
while(scanf("%d %d", &n, &m) && m && n){
for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
for(int i = 0; i < m; ++i) scanf("%d", &b[i]); sort(a, a+n); sort(b, b+m);
if(n > m){ printf("Loowater is doomed!\n"); continue; }//勇士太少,直接结束 int cnt = 0, cost = 0;
for(int i = 0; i < m; ++i)
if(b[i] >= a[cnt]){
cost += b[i];//记下费用
if(++cnt == n) break;//龙杀完了,提前退出
}
if(cnt < n) printf("Loowater is doomed!\n");
else printf("%d\n", cost);
}
return 0;
}
UVa 11292 Dragon of Loowater (水题,排序)的更多相关文章
- 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 贪心
贪心策略:一个直径为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 11636 Hello World! (水题思维)
题意:给你一个数,让你求需要复制粘贴多少次才能达到这个数. 析:这真是一个水题,相当水,很容易知道每次都翻倍,只要大于等于给定的数就ok了. 代码如下: #include <iostream&g ...
- Uva11292--------------(The Dragon of Loowater)勇者斗恶龙 (排序后贪心)
---恢复内容开始--- 题目: Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major ...
随机推荐
- NDK开发中的一个HTTP下载实例附带下载进度
有一个控制下载的管理类吧,调用http下载类进行各种下载,同时在下载过程中可以显示其下载的进度,而且在每个下载结束之后以类似回调的方式告诉管理类,以继续进行后续的操作. 直接代码: .h文件 #pra ...
- 树莓派3用create_ap变身无线AP
1.git clone https://github.com/oblique/create_ap.git2.cd create_ap3.sudo make install就这样安装好了4.接下来安装依 ...
- 常用类一一基本数据类型的包装类(WrapperClass)一一Byte Short nteger Long Float Double Character Boolean
为什么需要包装类? JAVA是支持跨平台的.可以在服务器 也可以在手机上运行 基本数据类型 在栈中 效率更高 包装类 将数据类型转换成对象 在 堆中 利于操作 package cn.bjsxt.w ...
- Unknown column in 'field list'
好久都没有亲手写数据库的连接以及操作了,近期一直都是用ejb,直接就映射到数据库了,所以关于jdbc的知识都忘得差不多了.不过吧,为了学习struts2,还是重新将jdbc知识捡起来.找了一上午的错误 ...
- Hadoop 初始化系统
hadoop namenode -format 或者 hdfs namenode -format 2.执行hadoop sbin 目录下的 start-dfs.sh start-yarn.sh3.查看 ...
- electron 截图为空
https://github.com/electron/electron/issues/2610
- https 证书传递、验证和数据加密、解密过程解析
我们都知道HTTPS能够加密信息,以免敏感信息被第三方获取.所以很多银行网站或电子邮箱等等安全级别较高的服务都会采用HTTPS协议. HTTPS简介 HTTPS其实是有两部分组成:HTTP + SSL ...
- Maven(一)——Maven入门
一.Maven的基本概念 Maven(翻译为"专家","内行")是跨平台的项目管理工具.主要服务于基于Java平台的项目构建,依赖管理和项目信息管理. 1.1. ...
- Web标准:七、横向导航菜单
Web标准:七.横向导航菜单 知识点: 1.横向列表菜单 2.用图片美化的横向导航 3.css Sprites 1)横向列表菜单 可以在第四节课的基础上来实现横向导航菜单,只要给li一个float ...
- byte,short,int,long数据之间的倍数关系
基本数据类型 byte = -128和127------------------------------------------------------------2的8次方,1个字节 shor ...