勇者斗恶龙UVa11292 - Dragon of Loowater
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2267
有一条n个头的恶龙,现在有m个骑士可以雇佣去杀死他,一个能力值为x的勇士可以砍掉直径不超过x的头,而且需要支付x个金币。如何雇佣才能砍掉所有的头且支付最少的金币,注意一个勇士只能砍一个头,也只能被雇佣一次。
输入包含多组数据,每组数据第一行为正整数n,m(1<=n,m<=20000),以下n行每行为一个整数,就是恶龙的头的直径,以下m行每行为一个整数,就是每个骑士的能力值。输入结束标志位m=n=0。
输出格式对于每组数据输出最少花费,如果无解,则输出"Loowater is doomed!"。
输入样例
2 3
5
4
7
8
4
2 1
5
5
10
0 0
这个题意思是挺好理解的,就是x>=n,而且x不能重复使用,本来我是按照习惯
for(int i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(b[j]>=a[i])
{
s=s+b[j];
break;
}
}
}
好吧,后来又想x只能用一次啊,然后就改成j=i,但是结果还是不对,然后想数据,发现还是不行,就看了一下书,他是把j放在前面的,
然后就改成了这个
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n,i,m,a[20000],b[20000];
while(cin>>n>>m)
{
if(n==0&&m==0)
break;
int s=0;
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(int j=0;j<m;j++)
{
cin>>b[j];
}
sort(a,a+n);
sort(b,b+m);
for(int j=0;j<m;j++)
{
for(i=j;i<n;i++)
{
if(b[j]>=a[i])
{
s=s+b[j];
break;
}
}
}
if(i<n||s==0)
{
cout<<"Loowater is doomed!"<<endl;
}
else
cout<<s<<endl;
}
return 0;
}
最后判断输出什么是如果骑士的个数少于恶龙的头,那么无论怎么样都不行,如果s==0那也代表没办法
哎,好多天没打代码了,什么都忘了,今天下定决心好好好学。
勇者斗恶龙UVa11292 - Dragon of Loowater的更多相关文章
- uva11292 Dragon of Loowater
水题,排序遍历即可 #include<iostream> #include<cstdio> #include<algorithm> using namespace ...
- uva11292 Dragon of Loowater(排序后贪心)
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...
- UVa 11292 勇者斗恶龙(The Dragon of Loowater)
首先先看一下这道题的英文原版... 好吧,没看懂... 大体意思就是: 有一条n个头的恶龙,现在有m个骑士可以雇佣去杀死他,一个能力值为x的勇士可以砍掉直径不超过x的头,而且需要支付x个金币.如何雇佣 ...
- 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 ...
- uva 11292 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 ...
- Dragon of Loowater
option=com_onlinejudge&Itemid=8&page=show_problem&problem=2267" style="color:b ...
随机推荐
- AI PRO I 第4章
Behavior Selection Algorithms An Overview Michael Dawe, Steve Gargolinski, Luke Dicken, Troy Humphre ...
- fenye
<div class="ptb20 navpages"> <span class=" ">共有<span class=" ...
- python学习道路(day6note)(time &datetime,random,shutil,shelve,xml处理,configparser,hashlib,logging模块,re正则表达式)
1.tiim模块,因为方法较多我就写在code里面了,后面有注释 #!/usr/bin/env python #_*_coding:utf-8_*_ print("time".ce ...
- java基础总结——概述
一.java语言概述 来自维基百科 https://zh.wikipedia.org/wiki/Java Java是一种计算机编程语言,拥有跨平台.面向对象.泛型编程的特性,广泛应用于企业级Web ...
- rabbitmq method之basic.consume
basic.consume指的是channel在 某个队列上注册消费者,那在这个队列有消息来了之后,就会把消息转发到给此channel处理,如果 这个队列有多个消费者,则会采用轮转的方式将消息分发给消 ...
- 去除select的样式
select::-ms-expand { display: none } .info-select { width: 88px; height: 25px; border: none; outline ...
- canvas 拖拽实现
Canvas 依赖分辨率 不支持事件处理器 弱的文本渲染能力 能够以 .png 或 .jpg 格式保存结果图像 最适合图像密集型的游戏,其中的许多对象会被频繁重绘 SVG 不依赖分辨率 支持事件处理器 ...
- HTTP缓存&代理
一.与缓存有关的Header 1.Request If-Modified-Since: 缓存文件的最后修改时间 If-None-Match: ...
- pixelmator处理png图片,处理掉过白的留白。
作为一个CTO,还是得学会一些普通的修图技术的.这不,刚学会在pixelmator下如何处理png中过多的留白. 汗,其实就是一个菜单选项而已./image/trim canvas 效果如下:
- CSS中定位和浮动对行内元素的宽高的影响
行内元素的大小是由元素里面的内容撑开的宽高决定的,就算在css中对行内元素设置width,height.行内元素也会忽略宽高的设置. 但是当行内元素使用position:absolute或者posit ...