UVA - 11292 Dragon of Loowater 贪心
贪心策略:一个直径为X的头颅,应该让雇佣费用满足大于等于X且最小的骑士来砍掉,这样才能使得花费最少。
AC代码
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <utility>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define eps 1e-10
#define inf 0x3f3f3f3f
#define PI pair<int, int>
typedef long long LL;
const int maxn = 2e4 + 5;
int head[maxn], kill[maxn];
int main() {
int n, m;
while(scanf("%d%d", &n, &m) == 2 && n && m) {
for(int i = 0; i < n; ++i) scanf("%d", &head[i]);
for(int i = 0; i < m; ++i) scanf("%d", &kill[i]);
sort(head, head + n);
sort(kill, kill + m);
int cnt = 0, cost = 0;
for(int i = 0; i < m; ++i) {
if(kill[i] >= head[cnt]) {
++cnt;
cost += kill[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 (水题,排序)
题意:有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 ...
随机推荐
- Linux常用命令(二)--文件目录命令
1. 列表目录命令: 格式: ls [参数] 用于显示文件或目录信息 选项: -l 每行显示一个文件和目录信息(长格式),简写:ll等同于ls -l 注意:当参数是文件时,显示此文件全部信息 当参数是 ...
- IO (五)
1 序列化和反序列化 1.1 ObjectOutputStream 序列化 1.1.1 概述 ObjectOutputStream将Java对象的基本数据写入OutputStream,可以使用Obje ...
- 将本地目录上传值git仓库
创建git仓库 以github为例,登录账号建立一个仓库,然后将仓库地址copy下来. 本地目录 初始化 $ git init 添加至版本库 $ git add -A 提交 $ git commit ...
- c# 对象 & 类
类定义中可以使用的访问修饰符组合 none or internal 类只能在当前工程中访问 public 类可以在任何地方访问 abstract or internal abstract 类只能在当前 ...
- python之闭包与装饰器
python闭包与装饰器 闭包 在函数内部定义的函数包含对外部的作用域,而不是全局作用域名字的引用,这样的函数叫做闭包函数. 示例: #-------------------------------- ...
- 移动端的弹窗滚动禁止body滚动
前言 最近一个需求是弹窗展示列表,显然是需要一个滚动条的,而滚动到底部就会穿透到body滚动,而阻止默认行为是不行的,这样两个都滑动不了 所以我在点击出现弹窗的时候在body加了以下css让它没有滚动 ...
- Python基础篇(六)
retun空值,后面的语句将不再被执行 >>> def test(): ... print("just a test!") ... return .. ...
- python基础 列表 的使用
列表 首先定义一个列表 声明列表 列表名字=[值1,值2] list=[1,2,3,4,5] 这是一个列表,列表中有五个元素(1,2,3,4,5) 显示list列表 print list 输出 ...
- Python之CVXOPT模块
Python中支持Convex Optimization(凸规划)的模块为CVXOPT,其安装方式为: 卸载原Pyhon中的Numpy 安装CVXOPT的whl文件,链接为:https://www ...
- 豹哥嵌入式好讲堂:ARM Cortex-M调试过程探析(1)- 4线接口标准(JTAG)
大家好,我是豹哥,猎豹的豹,犀利哥的哥.今天豹哥给大家讲的是嵌入式调试里的接口标准JTAG. 在结束<ARM Cortex-M开发文件详解>系列文章之后,豹哥修整了一小段时间,但是讲课的心 ...