题目大意:

你的王国里有一条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. activemq安装运行及其在springboot中的queue和topic使用

    安装activemq 运行 springboot使用 依赖 配置 Producer Consumer ComsumerTopic 使用 安装activemq http://activemq.apach ...

  2. ATL向控件添加私有属性-成员变量

    https://msdn.microsoft.com/zh-cn/library/cc451389(v=vs.71).aspx ------------------------------------ ...

  3. sublime添加右键菜单

    参考:https://www.zhihu.com/question/29662273/answer/45277925 @echo Off :START CLS echo *============== ...

  4. centos7 qt之程序编译 cant start process “cmake”

    之所以出现这个问题,是由于qt内置的cmake与系统已安装的cmake命令冲突.解决的方法是,在build里将cmake命令加上绝对路径. 问题得以解决.

  5. libevent源码深度剖析四

    libevent源码深度剖析四 ——libevent源代码文件组织 1 前言 详细分析源代码之前,如果能对其代码文件的基本结构有个大概的认识和分类,对于代码的分析将是大有裨益的.本节内容不多,我想并不 ...

  6. 关于windows的锁定状态

    本来以为要在项目里用上的,现在看来不需要了,把相关的函数列一下吧,以后如果用到了,再写详细点 锁定计算机 : LockWorkStation 注册Windows状态变化的监听函数: BOOL WTSR ...

  7. SpringBoot26 RestTemplate、WebClient

    1 RestTemplate RestTemplate是在客户端访问 Restful 服务的一个核心类:RestTemplate通过提供回调方法和允许配置信息转换器来实现个性化定制RestTempla ...

  8. 浅析junit4及扩展实践

    junit框架相关源代码分析,网上已经有很多了,本篇不做过多相关解说,主要还是要自己多读相关源代码.本篇主要对自动化测试过程相关的测试用例,测试数据,测试结果结合junit做相关扩展说明. 如果要解读 ...

  9. c# 获取客户端ip、mac、机器名、操作系统、浏览器信息

    d using System; using System.Collections.Generic; using System.Linq; using System.Web; using System. ...

  10. golang学习

    1. 学习资源列表 https://github.com/golang/go/wiki 2. 最快的入门方法 直接通过代码学习 https://tour.go-zh.org 3. go指南 https ...