勇者斗恶龙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 ...
随机推荐
- “菜”鸟理解.NET Framework(CLI,CLR,CTS,CLS,BCL,FCL)
既然要学.NET,就要先认识认识她,我不喜欢大段大段文字的东西,自己通过理解,画个图,来看看.NET的沉鱼落雁,闭月羞花之容. 最下层蓝色部分是.NET Framework的基础,也是所有应用软件的基 ...
- python学习道路(day12note)(mysql操作,python链接mysql,redis)
1,针对mysql操作 SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass'); 设置密码 update user set password ...
- 事务处理-回滚(转账操作)(转自http://www.cnblogs.com/void-m/p/6143540.html)
JDBC事务处理-四大原则 原子性一致性隔离性持久性 第一步:实现转账操作 假设在账户中,盖伦有余额5000元,赵信有余额2000元, 盖伦要向赵信转账1000元. 1 2 3 4 5 6 7 8 9 ...
- Urimoo做试卷
Urimoo做试卷 题目描述 SBJ最近收到了n张数学卷子,这些卷子的标号为0-n−1,他不想写这些卷子,于是他的好朋友SCX热心地想要帮他撕掉n−1张卷子.SBJ很高兴,但是SCX说,他撕试卷的顺序 ...
- Magento学习第一课——目录结构介绍
Magento学习第一课--目录结构介绍 一.Magento为何强大 Magento是在Zend框架基础上建立起来的,这点保证了代码的安全性及稳定性.选择Zend的原因有很多,但是最基本的是因为zen ...
- source insight增加注释宏
打开base项目,下main.c文件里加入以下代码 对于在一行内的局部注释, 没有找到解除注释的宏, macro Comments_orUn_gx() { //用杠星注释多行,或取消杠星注释 ,不选中 ...
- ios导航器跳转动画
出栈或压栈简单实现动画 CATransition *animation1=[CATransition animation];//类方法创建一个切换对象 animation1.duratio ...
- LeetCode First Unique Character in a String
原题链接在这里:https://leetcode.com/problems/first-unique-character-in-a-string/ 题目: Given a string, find t ...
- vim - line
copy complete current line: yy replace a char (e.g. comma) to new line: %s/,/\r/g
- ubuntu-14.04服务器版下搭建apache2+svn+svnmanager服务
本人linux小白,新进公司,被分配此任务,好崩溃,只能一边百度linux命令一边完成任务.从装系统开始一直到搭建好服务,也快一周了,足见水平之差,以下博文基本靠网络,再加上自己的摸索,直至搭建成功. ...