uva11292 Dragon of Loowater(排序后贪心)
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define pii pair<int,int>
#define LL long long int
const int eps=1e-;
const int INF=;
const int maxn=+;
int n,m,a[maxn],b[maxn],sum;
int main()
{
//freopen("in1.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%d%d",&n,&m)==)
{
if(m==&&n==)
{
break;
}
else
{
sum=;
for(int i=; i<n; i++)
{
scanf("%d",&a[i]);
}
for(int i=; i<m; i++)
{
scanf("%d",&b[i]);
}
if(n>m)
{
printf("Loowater is doomed!\n");
}
else
{
int tn=n,tm=m,j=,i=;
sort(a,a+n);
sort(b,b+m);
for(i=; i<n; i++)
{
if(tn>tm||j>=m)
{
break;
}
else
{
for(; j<m; j++)
{
if(a[i]<=b[j])
{
sum+=b[j];
tm--;
tn--;
j++;
/*这里的j++非常重要,必须加,因为不加
的话下一次循环还是先从上次这个j开始判断一
遍再进行下一次循环。(如果for里写成
++j效果和j++一样的),这也是for循环
中易犯的错误。*/
break;
}
else
{
tm--;
}
}
}
}
if(i==n)
{
printf("%d\n",sum);
}
else
{
printf("Loowater is doomed!\n");
}
}
}
}
//fclose(stdin);
//fclose(stdout);
return ;
}
uva11292 Dragon of Loowater(排序后贪心)的更多相关文章
- Uva11292--------------(The Dragon of Loowater)勇者斗恶龙 (排序后贪心)
---恢复内容开始--- 题目: Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major ...
- UVa 11292 - Dragon of Loowater(排序贪心)
Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem.The shore ...
- uva11292 Dragon of Loowater
水题,排序遍历即可 #include<iostream> #include<cstdio> #include<algorithm> using namespace ...
- Problem #3263 丽娃河的狼人传说 区间满足灯数,r排序后贪心。
丽娃河的狼人传说 Time limit per test: 1.0 seconds Time limit all tests: 1.0 seconds Memory limit: megabytes ...
- 勇者斗恶龙UVa11292 - Dragon of Loowater
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=s ...
- Summer sell-off CodeForces - 810B (排序后贪心)
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying ...
- 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 The Dragon of Loowater
题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...
- 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 ...
随机推荐
- 鸟哥的Linux私房菜-第一部分-第3章主机规划与磁盘分区
1. 选择一个与你的Linux搭配的主机配置 NAT服务器:小型企业或者学校都基本是只有一条对外的线路,网卡 SAMBA服务器:完成Windows网上邻居的功能,网卡和硬盘要求高 Mail服务器:如果 ...
- 【python】判断字符串以什么开头或结尾
项目中用到python判断一个字符串是否以某个字符串结尾,比如,筛选一个目录下所有以.mp4结尾的文件. >>> item = "demo.mp4" >&g ...
- mysql终结篇
一.mysql中not null unique和primary key 的区别 1.not null unique 是给一个字段设置非空且唯一的特性,当表中字段没有设置primary key的主键特性 ...
- Shell字符串操作
@1:子串削除 ${string#substring} 从$string 的开头位置截掉最短匹配的$substring. ${string##substring} 从$string 的开头位置截掉最长 ...
- LVS Nginx Haproxy对比
一般对负载均衡的使用是随着网站规模的提升根据不同的阶段来使用不同的技术. 具体的应用需求还得具体分析,如果是中小型的Web应用,比如日PV小于1000万,用Nginx就完全可以了: 如果机器不少,可以 ...
- MySQL数据库(1)_MySQL数据库介绍与安装
一.数据库相关概念的简介 数据库(database,DB)是指长期存储在计算机内的,有组织,可共享的数据的集合.数据库中的数据按一定的数学模型组织.描述和存储,具有较小的冗余,较高的数据独立性和易扩展 ...
- git 分支合并处理
Git 分支 - 分支的新建与合并 https://git-scm.com/book/zh/v2/%E8%B5%B7%E6%AD%A5-%E5%85%B3%E4%BA%8E%E7%89%88%E6%9 ...
- 谷歌浏览器安装jsonview插件方法
参考https://www.cnblogs.com/whycxb/p/7126116.html,已安装成功.
- linux上安装程序出现的问题汇总
1.程序在编译过程中出现:variable set but not used [-Werror=unused-but-set-variable] 解决方法:将configure文件和Makefile文 ...
- QGIS3.0.3+Qt5.9+VS2015_x64编译
QGIS3.0.3+Qt5.9+VS2015_x64编译 参考:https://blog.csdn.net/u010670734/article/details/80241615 https://ww ...