uva11292 Dragon of Loowater(排序后贪心)
2024-09-02 22:33:38
#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 ;
}
最新文章
- EntityFramework错误:Unable to update the EntitySet because it has a DefiningQuery
- python os.path模块
- 如果用css的border属性画一个三角形
- Python基础、异常处理
- C# 不同版本切版时,方法不支持,加载对应dll, 相关Dll的资源
- 自定义控件--CircleImageView(类似于QQ、微信圆形头像自定义控件)
- Linux之convert命令
- Java实现分页数据获取CachedRowSet
- POJ 3694 LCA
- Jmeter+badboy环境搭建
- ADO.NET知识点
- 【实验吧】CTF_Web_简单的SQL注入之3
- OpenCV——PS图层混合算法(六)
- 基于C#简单实现多个word文件和Excel文件的全局字符串替换
- CF1108F MST Unification
- Mysql建库建用户建表等常用命令
- 使用xshell+xmanager+pycharm搭建pytorch远程调试开发环境
- [转]springboot2 webflux 响应式编程学习路径
- 在VS2017上使用C#调用非托管C++生成的DLL文件(图文讲解)
- 第一讲(3)osgearth编译
热门文章
- django基本安装
- Hadoop学习基础之三:MapReduce
- Hibernate Student_Course_Score设计
- springboot-整合freemarker
- Delphi中ComPort通信中的数据处理
- Python编程-网络编程进阶(IO复用、Socketserver)
- oracle长连接超时设置
- 快乐学习 Ionic Framework+PhoneGap 手册1-5 {IO开关}
- redis 第一篇
- Centos6.5使用yum安装软件的时候 Another app is currently holding the yum lock; waiting for it to exit...