【题解】 UVa11292 The Dragon of Loowater
题目大意:
你的王国里有一条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的更多相关文章
- 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 ...
- The Dragon of Loowater
The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into ...
- uva 11292 Dragon of Loowater (勇者斗恶龙)
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- UVA它11292 - Dragon of Loowater
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- UVA 11292 Dragon of Loowater(简单贪心)
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- Dragon of Loowater
option=com_onlinejudge&Itemid=8&page=show_problem&problem=2267" style="color:b ...
- 贪心/思维题 UVA 11292 The Dragon of Loowater
题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...
- 勇者斗恶龙UVa11292 - Dragon of Loowater
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=s ...
- uva11292 Dragon of Loowater
水题,排序遍历即可 #include<iostream> #include<cstdio> #include<algorithm> using namespace ...
随机推荐
- Jenkins修改端口号(windows系统)
windows下改端口号: Jenkins安装成功后,默认的端口为8080. 如果该端口号与其他服务的端口号冲突,则需要更改Jenkins的端口号. 具体方法为: 修改Jenkins安装目录下的 je ...
- __CLASS__
<?php class base_class { function say_a() { echo "'a' - said the " . __CLASS__ . " ...
- windows环境下,安装zookeeper~
1. 概述 ZooKeeper是Hadoop的正式子项目,它是一个针对大型分布式系统的可靠协调系统,提供的功能包括:配置维护.名字服务.分布式同步.组服务等.ZooKeeper的目标就是封装好复杂 ...
- 为工具箱添加CSKin选项卡
如何使用CSKin 项目的引用→右键→添加; 找到SCKin.dll; 添加引用 工具箱新建一个选项卡; 工具箱的空白处→右键→添加选项卡→SKinControl, 将刚才的CSKin.dll 直接拖 ...
- jmeter json截取
前些日子压测我们系统,发现我们开发把cookie值当成一个参数返回到了json中,这样就要从json中获取这个cookie后配置到cookie 管理器中 Jmeter中本身是不支持直接处理json串的 ...
- Linux - apache 服务
暂时关闭 iptables 防火墙 [root@sch01ar ~]# systemctl stop iptables.service 暂时关闭 firewall 防火墙 [root@sch01ar ...
- 当我们谈 SQL 优化时在谈些什么?
作者 |孙银行编辑 | 顾乡 背景 Mysql数据库作为数据持久化的存储系统,在实际业务中应用广泛.在应用也经常会因为SQL遇到各种各样的瓶颈.最常用的Mysql引擎是innodb,索引类型是B-Tr ...
- 前端工作准备-foxmail登陆失败汇总
foxmail 管理邮箱账号的一个工具软件, 但是在登陆的时候总是遇到明明账号密码没有问题,却总是报错,这里我登陆的时候的集中解决方法总结下: pop和imap 是邮箱的两种协议,大多选imap协议, ...
- java实现 数组中两个元素相加等于指定数的所有组合
package com.algorithm.hash; public class alg1 { public static void main(String argv[]) { int[] arr ...
- mac下怎样删除冗余的环境变量?echo $PATH
记下$PATH变量中冗余路径所处顺序,例如: /Users/zhang/.rvm/gems/ruby-2.1.2/bin:/Users/zhang/.rvm/gems/ruby-2.1.2@globa ...