题意:有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 (水题,排序)的更多相关文章

  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 贪心

    贪心策略:一个直径为X的头颅,应该让雇佣费用满足大于等于X且最小的骑士来砍掉,这样才能使得花费最少. AC代码 #include <cstdio> #include <cmath&g ...

  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 11636 Hello World! (水题思维)

    题意:给你一个数,让你求需要复制粘贴多少次才能达到这个数. 析:这真是一个水题,相当水,很容易知道每次都翻倍,只要大于等于给定的数就ok了. 代码如下: #include <iostream&g ...

  9. Uva11292--------------(The Dragon of Loowater)勇者斗恶龙 (排序后贪心)

    ---恢复内容开始--- 题目: Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major ...

随机推荐

  1. 修改mysql的用户密码

    修改的用户都以root为列.一.拥有原来的myql的root的密码: 方法一: #mysql -u root mysql> SET PASSWORD FOR 'root'@'localhost' ...

  2. StringUtil字符串工具类

    package com.zjx.test03; /** * 字符串工具类 * @author * */ public class StringUtil { /** * 判断是否是空 * @param ...

  3. 跨越数据库操作时注意要加dbo

    跨越数据库操作时注意要加dbo insert into hrdb.dbo.TB_B_PROJECTS  :这样是正确的 insert into hrdb.TB_B_PROJECTS  :这样是错误的

  4. STS或eclipse安装SVN插件

    安装sts--SVN插件 简介:sts是与eclipse类似的Java IDE开发工具(不了解的百度) 1.sts菜单栏 help->install New Software 依据大家的版本选择 ...

  5. ArcGIS案例学习笔记3_1

    ArcGIS案例学习笔记3_1 联系方式:谢老师,135_4855_4328,xiexiaokui#139.com 时间:第三天上午 内容1:ArcGIS 平台介绍 体系结构 Arcgis for d ...

  6. Python中文件编码的检测

    前言: 文件打开的原则是“ 以什么编码格式保存的,就以什么编码格式打开 ”,我们常见的文件一般是以“ utf-8 ”或“ GBK ”编码进行保存的,由于编辑器一般设置了默认的保存和打开方式,所以我们在 ...

  7. docker 配置远程访问

    系统: centos 7 Docker version 1.12.6 yum 安装的  #yum install docker docker server在192.168.111.120上 # vim ...

  8. Java8 Map的遍历方式

    在这篇文章中,我将对Map的遍历方式做一个对比和总结,将分别从JAVA8之前和JAVA8做一个遍历方式的对比,亲测可行. public class LambdaMap { private Map< ...

  9. 删除Eclipse已有的SVN资源库位置

    点击Eclipse菜单栏的[Window]->[Show View]->[Other],在弹出的对话框中,选择[SVN]->[SVN资源库],然后点击[OK]. 接着,在Eclips ...

  10. C#中货币类型和数值类型、字符串类型的转化

    1.定义textbox的数据 private void Form1_Load(object sender, EventArgs e) { this.textBox1.Text = String.For ...