题目大意:

你的王国里有一条n个头的恶龙,你希望雇佣一些骑士把它杀死(即砍掉所有头)。村里有m个骑士可以雇佣,一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x个金币。如何雇佣骑士才能砍掉龙的所有头,且需要支付的金币最少?注意,一个骑士只能砍一个头。(且不能被雇佣两次)。 输入格式

输入包含多组数据。每组数据的第一行为正整数n和m(1<=n,m<=20000);以下n行每行为一个整数,即恶龙每个头的直径;以下m行每行为一个整数,即每个骑士的能力。输入结束标志为n=m=0。 输出格式

对于每组数据,输出最小花费。如果无解,输出“Loowater is doomed!”。

Solution

显然我们要让勇士砍最适合他的龙,所以就考虑直接排序+贪心就好了...

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<queue>
#define ll long long
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
using namespace std;
inline int gi(){
int sum=0,f=1;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')f=-f;ch=getchar();}
while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
return f*sum;
}
inline ll gl(){
ll sum=0,f=1;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')f=-f;ch=getchar();}
while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
return f*sum;
}
const int N=20010;
int a[N],b[N];
int main(){
int i,j,n,m,k;
while(scanf("%d%d",&n,&m)==2 && n && m){
for(i=1;i<=n;i++)a[i]=gi();
for(i=1;i<=m;i++)b[i]=gi();
sort(a+1,a+n+1);sort(b+1,b+m+1);
int t=1;ll ans=0;
for(i=1;i<=m && t<=n;i++){
if(a[t]>b[i])continue;
ans+=b[i];t++;
}
if(t>n)printf("%lld\n",ans);
else puts("Loowater is doomed!");
}
return 0;
}

【题解】 UVa11292 The Dragon of Loowater的更多相关文章

  1. uva-----11292 The Dragon of Loowater

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

  2. The Dragon of Loowater

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

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

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

  4. UVA它11292 - Dragon of Loowater

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

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

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

  6. Dragon of Loowater

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=2267" style="color:b ...

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

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

  8. 勇者斗恶龙UVa11292 - Dragon of Loowater

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=s ...

  9. uva11292 Dragon of Loowater

    水题,排序遍历即可 #include<iostream> #include<cstdio> #include<algorithm> using namespace ...

随机推荐

  1. 使用模板创建第一个Web API项目

    软件环境 vs 2015 update3 本节将通过例子讲述创建Web API 项目的方法 第一步,打开vs ,依次通过[文件]菜单,[新建][项目]命令,大致步骤如下图 :   第2步,在弹出对话框 ...

  2. C#多线程List的非线程安全性

    背景:最近在做多线程方面的工作,工作中发现多线程中很多坑,这里就有一个List添加对象的误区,这里做个分享跟大家讲讲这个坑是怎么形成的怎么样避免. 示例: 代码及错误: 如果单单只从程序逻辑上看,应该 ...

  3. 安全测试回顾(一)补充:burp 的基本操作

    浏览器设置; 拦截请求: Spider 伪造请求: 对这个url 伪造请求 拦截一个页面后,进入攻击模块 sniper  两个参数值 保证一个不变  另一个 进行枚举 battering ram 两个 ...

  4. python's fourth day for me 列表

    break 可以打断 for 循环不执行 else 语句 s = 'fdddsadwes' for i in s: if i == 's': break #可跳出for循环且不用执行else语句 pr ...

  5. js操作window

    js操作window 常用属性 window.closed // window是否关闭 window.length // iframe个数 window.name // 获取和设置window的名字 ...

  6. ndnarry元素处理

    元素计算函数 ceil(): 向上最接近的整数,参数是 number 或 array floor(): 向下最接近的整数,参数是 number 或 array rint(): 四舍五入,参数是 num ...

  7. JDBC概述及连接数据库

    一.JDBC简介:  JDBC(Java Data Connectivity,java数据库连接)是一种用于执行sql语句的JavaAPI,可以为多种关系数据库提供统一访问,它由一组用Java语言编写 ...

  8. C#读写EXCEL(二)

    C#读写EXCEL(二) -- ::| 分类: 默认分类 | 标签: |举报 |字号大 中 小 订阅 用微信 “扫一扫” 将文章分享到朋友圈. 用易信 “扫一扫” 将文章分享到朋友圈. 下载LOFTE ...

  9. leetcode375

    public class Solution { public int GetMoneyAmount(int n) { , n + ]; , n); } int DP(int[,] t, int s, ...

  10. OK6410&nbsp;linux系统遇到的BUG总结

    经过一段时间使用OK6410 256M RAM 2G nand Flash碰见了不少问题. 所以特意开本贴一起交流.大家有什么BUG解决的可以跟上本帖.求助的请另开贴.勿跟本帖.谢谢.请谅解!!! 希 ...