题意:有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. 练习:自己写一个容器ArrayList集合 一一数组综合练习

    package cn.bjsxt.myCollection; import java.util.Arrays; /** * 天下文章一大抄,看你会抄不会抄. * 模拟Stringbuilder 写一个 ...

  2. 关于关闭TAB,IFRAME占用的内存不能释放问题

    资料来源:http://jxd-zxf.iteye.com/blog/1440611 使用TAB时注意,如果TAB是引用IFRAME,关闭TAB时IFRAME不会被销毁从而导致内存不能释放,大量使用T ...

  3. function方法控制是否隐藏部分内容

    $(document).ready(function() { $('input[type=radio][name=IE]').change(function() { if (this.value == ...

  4. Zabbix 监控端口状态并邮件报警

    Zabbix监控端口 前提 zabbix安装 zabbix邮件报警 添加监控项 添加触发器 添加动作 设置完成后,在配置过报警媒介后也就是 邮件报警  后就完成了.

  5. Spark之 Spark Streaming整合kafka(Java实现版本)

    pom依赖 <properties> <scala.version>2.11.8</scala.version> <hadoop.version>2.7 ...

  6. 树莓派项目——基于树莓派的WIFI网络互传系统设计

    一 实验原理 所需硬件:树莓派3B,TP-LINK WiFi模块,笔记本电脑,网线 所需软件:Putty.远程桌面链接.python.cmd界面 树莓派3B是只有信用卡大小的微型电脑,其系统基于Lin ...

  7. K组翻转链表 · Reverse Nodes in k-Group

    [抄题]: 给你一个链表以及一个k,将这个链表从头指针开始每k个翻转一下.链表元素个数不是k的倍数,最后剩余的不用翻转. [思维问题]: [一句话思路]: // reverse head->n1 ...

  8. 【Spring】Spring boot多数据源历险记

    一.问题描述 笔者根据需求在开发过程中,需要在原项目的基础上(单数据源),新增一个数据源C,根据C数据源来实现业务.至于为什么不新建一个项目,大概是因为这只是个小功能,访问量不大,不需要单独申请个服务 ...

  9. js Array Map and Set

    Array slice slice()就是对应String的substring()版本,它截取Array的部分元素,然后返回一个新的Array: var arr = ['A', 'B', 'C', ' ...

  10. 表单数据转换成json格式数据

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...