题意:有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. UI5-文档-4.18-Icons

    我们的对话框仍然是空的.因为SAPUI5附带了一个包含500多个图标的大图标字体,所以我们将在对话框打开时添加一个图标来问候用户. Preview An icon is now displayed i ...

  2. 删除数据恢复数据语句 Oracle

    SELECT * FROM TBL_DZYJ_GEORELICSINFO AS OF TIMESTAMP TO_TIMESTAMP('2017-5-8 9:00:00','YYYY-MM-DD HH: ...

  3. 代码报错记录-MAVEN

    报错: COMPILATION ERROR : 程序包不存在. 说是找不到程序包,我的JUNIT是父项目中的,子项目是从JAVA项目转为MAVEN项目的,难道在转成MAVEN项目时对POM文件的修改有 ...

  4. C++ 11 中的 Lambda 表达式的使用

    Lambda在C#中使用得非常频繁,并且可以使代码变得简洁,优雅. 在C++11 中也加入了 Lambda. 它是这个样子的 [] () {}...  是的三种括号开会的节奏~ [] 的作用是表示La ...

  5. pyplot绘图区域

    pyplot绘图区域 Matplotlib图像组成 matplotlib中,整个图像为一个Figure对象,与用户交互的整个窗口 Figure对象中包含一个或多个Axes(ax)子对象,每个ax子对象 ...

  6. 【Linux】svn环境配置

    Ubuntu 安装svn环境配置 1. 安装 sudo apt-get install subversion 安装过程需要数据[Y] 2. svn位置选择 安装完成之后,选择svn目录位置, 将其放在 ...

  7. HTML5 画图--文字

    1:html <div style="margin:0 auto;width:794px;height:1123px"> <canvas id="myC ...

  8. ubuntu中vim的设置

    问题:刚安装的VIM中,backspace不能删除字符,且上下左右箭头没反应. 解决方法: sudo vi  /etc/vim/vimrc.tiny 修改 set compatible为set noc ...

  9. 关于空指针NULL、野指针、通用指针

    http://www.cnblogs.com/losesea/archive/2012/11/16/2772590.html 首先说一下什么是指针,只要明白了指针的含义,你就明白null的含义了.假设 ...

  10. php 下 html5 XHR2 + FormData + File API 上传文件

    FormData的作用: FormData对象可以帮助我们自动的打包表单数据,通过XMLHttpRequest的send()方法来提交表单.当然FormData也可以动态的append数据.FormD ...