贪心策略:一个直径为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 贪心的更多相关文章

  1. UVA 11292 Dragon of Loowater(简单贪心)

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  2. uva 11292 Dragon of Loowater (勇者斗恶龙)

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  3. [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 ...

  4. UVa 11292 - Dragon of Loowater(排序贪心)

    Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem.The shore ...

  5. UVa 11292 Dragon of Loowater

    简单贪心 龙头的直径和人的佣金排序,价值小的人和直径小的配 #include<iostream> #include<cstdio> #include<cmath> ...

  6. UVa 11292 Dragon of Loowater (水题,排序)

    题意:有n个条龙,在雇佣勇士去杀,每个勇士能力值为x,只能杀死头的直径y小于或等于自己能力值的龙,只能被雇佣一次,并且你要给x赏金,求最少的赏金. 析:很简单么,很明显,能力值高的杀直径大的,低的杀直 ...

  7. UVA它11292 - Dragon of Loowater

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  8. uva 11292 The Dragon of Loowater(贪心)

    题目大意:   你的王国里有一条n个头的恶龙,你希望雇一些骑士把它杀死(即砍掉所有头).村里有m个骑士可以雇佣,一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x个金币.如何雇佣骑士才 ...

  9. 贪心/思维题 UVA 11292 The Dragon of Loowater

    题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...

随机推荐

  1. XML,HTML,XHTML

    对于上面3种技术,我们经常使用到,这里具体的做一个总结,来对比一下这3个东西. 什么是XML? XML即Extentsible Markup Language(可扩展标记语言),是用来定义其它语言的一 ...

  2. 【javaweb学习笔记】WEB02_HTML&CSS

    一.表单相关知识 1.表单: 所有需要提交到服务器端的表单项必须使用<form></form>括起来 form标签属性(有两个): 1)action,整个表单提交的位置(可以是 ...

  3. MYSQL导入大量数据碰到的问题及解决方法

    在项目中,经常会碰到往数据库中导入大量数据,以便利用sql进行数据分析.在导入数据的过程中会碰到一些需要解决的问题,这里结合导入一个大约4G的txt数据的实践,把碰到的问题以及解决方法展现出来,一方面 ...

  4. SQL Server错误严重性级别和异常处理

    关于SQL Server的错误严重性级别的说明,强烈认真看一下下面的两个链接 脱机帮助 ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.zh-CHS/sqlerrm9/html/ ...

  5. SQL语句-INSERT语句

    Insert语句 Insert语句三种写法: mysql> desc students; +-------+-------------+------+-----+---------+------ ...

  6. Android组件化框架设计与实践

    在目前移动互联网时代,每个 APP 就是流量入口,与过去 PC Web 浏览器时代不同的是,APP 的体验与迭代速度影响着用户的粘性,这同时也对从事移动开发人员提出更高要求,进而移动端框架也层出不穷. ...

  7. vs2012编译在win7 32位电脑和win xp电脑上运行的win32程序遇到的问题记录

    一.win7 32位电脑: vs2012编译的64位程序是没有问题的.但编译的32位程序在别的电脑(虚拟机模拟)出错: 感觉很无语,vs这么牛逼的东西,在设计时候都不考虑这些吗? 在自己电脑C:\Wi ...

  8. 爬取西刺网的免费IP

    在写爬虫时,经常需要切换IP,所以很有必要自已在数据维护库中维护一个IP池,这样,就可以在需用的时候随机切换IP,我的方法是爬取西刺网的免费IP,存入数据库中,然后在scrapy 工程中加入tools ...

  9. spring jdbc踩坑日记,new JdbcTemplate 为null导致UserDao一直为null

    private DataSource datasource; private JdbcTemplate jdbcTemplateObject; //设置注入 public void setdataso ...

  10. 自动化测试(二) 单元测试junit的Test注解突然不能使用原因以及解决方案

    做为一名刚接触自动化测试的人,才知道单元测试原来也挺有讲究的. 我塞,Test注解报错,没有道理啊~之前好好的,怎么会出现这样~ 原因如下,本人新建了个Test类,报错重名, 难怪提示Test不是注解 ...