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 ...
随机推荐
- orange安装文档
一.Orange简介 Orange是一个基于 OpenResty/Nginx 的 API Gateway,提供 API 及 “自定义规则” 的监控和管理,如访问统计.流量切分.AB 测试.API ...
- LeetCode-day03
28. Best Time to Buy and Sell Stock 买卖股票的最好时间 29. Best Time to Buy and Sell Stock II 买卖股票2(多次买入,一次卖出 ...
- jquery mobile 带参数跳转收集(紧个人使用,测试完会补全)
//临时存储 var TempCache = { cache:function(value){ localStorage.setItem("EasyWayTempCache",va ...
- Java 如何读取resources
Sample in Github 1.一般使用Maven创建Java工程,代码文件在src/main/java文件夹中,资源文件在src/main/resources文件夹中,Java代码为什么可以读 ...
- Python之异常处理(Day27)
一.错误和异常 part1: 1.语法错误(这种错误,根本过不了python解释器的语法检测,必须在程序执行前就改正) #语法错误示范一 if #语法错误示范二 def test: pass #语法错 ...
- 前端基础之css样式(选择器)
一.css概述 CSS是Cascading Style Sheets的简称,中文称为层叠样式表,对html标签的渲染和布局 CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明. 例如 二.c ...
- Linux Shell基础 单引号、双引号、反引号、小括号和大括号
单引号和双引号 单引号和双引号用于变量值出现空格时将字符用引号括起来. 二者的主要区别在于, 被单引号括起来的字符都是普通字符,就算特殊字符也不再有特殊含义: 被双引号括起来的字符中,"$& ...
- RHEL(或CentOS)中关于逻辑卷( Logical Volume Manager,LVM)的一些概念及使用LVM的例子
1.逻辑卷(logical volumes,LV) 卷管理在物理存储之上的抽象层,它使你能够创建逻辑存储卷.和直接使用物理存储相比,这从很多方面提供了更大的灵活性.比如,使用逻辑卷,你将不再受物理磁盘 ...
- 【TECH】CAS php客户端配置
搞完java又搞php,我整个人都不好了=.= 跟大师在linux上折腾了一下午,没调出来,早上在windows上跑通了,中午终于在linux上搞定了,嘿嘿. server端配置参见这里 在windo ...
- hi3515 rtc驱动(ds1307/1339)驱动和示例
将驱动放入/extdrv中编译 部分驱动如下: #include <linux/module.h> #include <linux/miscdevice.h>#include ...