L贪心基础
<span style="color:#330099;">/*
L - 贪心 基础
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit Status
Description
Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predators, the geese population was out of control. The people of Loowater mostly kept clear of the geese. Occasionally, a goose would attack one of the people, and perhaps bite off a finger or two, but in general, the people tolerated the geese as a minor nuisance. One day, a freak mutation occurred, and one of the geese spawned a multi-headed fire-breathing dragon. When the dragon grew up, he threatened to burn the Kingdom of Loowater to a crisp. Loowater had a major problem. The king was alarmed, and called on his knights to slay the dragon and save the kingdom. The knights explained: "To slay the dragon, we must chop off all its heads. Each knight can chop off one of the dragon's heads. The heads of the dragon are of different sizes. In order to chop off a head, a knight must be at least as tall as the diameter of the head. The knights' union demands that for chopping off a head, a knight must be paid a wage equal to one gold coin for each centimetre of the knight's height." Would there be enough knights to defeat the dragon? The king called on his advisors to help him decide how many and which knights to hire. After having lost a lot of money building Mir Park, the king wanted to minimize the expense of slaying the dragon. As one of the advisors, your job was to help the king. You took it very seriously: if you failed, you and the whole kingdom would be burnt to a crisp! Input
The input contains several test cases. The first line of each test case contains two integers between 1 and 20000 inclusive, indicating the number n of heads that the dragon has, and the number m of knights in the kingdom. The next n lines each contain an integer, and give the diameters of the dragon's heads, in centimetres. The following m lines each contain an integer, and specify the heights of the knights of Loowater, also in centimetres. The last test case is followed by a line containing: 0 0 Output
For each test case, output a line containing the minimum number of gold coins that the king needs to pay to slay the dragon. If it is not possible for the knights of Loowater to slay the dragon, output the line: Loowater is doomed! Sample Input
2 3
5
4
7
8
4
2 1
5
5
10
0 0
Sample Output
11
Loowater is doomed!
By Grant Yuan
2014.7.14
贪心
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int m,n;
int a[20001];
int b[20001];
int main()
{ int sum;
while(1){sum=0;
cin>>n>>m;
if(m==0&&n==0)
break;
for(int i=0;i<n;i++)
cin>>a[i];
for(int j=0;j<m;j++)
cin>>b[j];
if(m<n){
cout<<"Loowater is doomed!"<<endl;
}
else{
sort(a,a+n);
sort(b,b+m);
int i=0;
for(int j=0;j<m;j++)
{
if(b[j]>=a[i]){
i++;
sum+=b[j];}
if(i==n) break;}
if(i==n) cout<<sum<<endl;
else cout<<"Loowater is doomed!"<<endl;
}}
return 0;
}
</span>
L贪心基础的更多相关文章
- L - 贪心 基础
Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shor ...
- poj2709 贪心基础
D - 贪心 基础 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bi ...
- uva11292贪心基础题目
C - 贪心 基础 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bi ...
- hdu 1009 贪心基础题
B - 贪心 基础 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB 64bi ...
- Problem L: 搜索基础之马走日
Problem L: 搜索基础之马走日 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 134 Solved: 91[Submit][Status][W ...
- - > 贪心基础入门讲解一——完美字符串
约翰认为字符串的完美度等于它里面所有字母的完美度之和.每个字母的完美度可以由你来分配,不同字母的完美度不同,分别对应一个1-26之间的整数. 约翰不在乎字母大小写.(也就是说字母F和f)的完美度相同. ...
- BalkanOI 2018 Parentrises(贪心+基础DP)
题意 https://loj.ac/problem/2713 思路 对于 \(\text{P1}\) 的档,首先可以看出 \(O(n^3)\) 的方法,即用 \(O(n^3)\) 的 \(\text{ ...
- 股神小L [贪心]
题面 思路 股票题肯定是贪心或者$dp$啊 这个题比较$naive$,可以看出来你这里买股票的过程一定是能不买就不买,能卖就拣最贵的日子卖,而且时间不能倒流(废话= =||) 所以我们按照时间从前往后 ...
- - > 贪心基础入门讲解五——任务执行顺序
分析: 本题可以抽象成,从一个整数开始,每次减去a,再加上b (a,b都是正数),要求每次操作都不产生负数. 针对本题a[i] = R[i], b[i] = R[i] – O[i],注意O[i] &l ...
随机推荐
- SQL Server Backup & Restore
USE [master]; GO CREATE DATABASE test; GO CREATE DATABASE test2; GO BACKUP DATABASE test TO DISK = ' ...
- 添加无登录权限的SSH用户命令
useradd -M -s /sbin/nologin -n username passwd username userdel -r username
- spring返回@ResponseBody报406
HTTP Status 406 - type Status report message description The resource identified by this request is ...
- java二维码生成
import java.io.File; import java.nio.file.Path; import java.util.HashMap; import com.google.zxing.Ba ...
- C#.Net调用VB.Net中的MY
用过VB.NET的人应该只要MY有多强大了吧,是不是很想在C#中也能调用呢? 当然是可以的,.net作为微软的跨语言的平台,必须是能实现的,不然微软就自己打自己嘴巴了~ 回到正题上: 1.在程序中加上 ...
- EF错误
The model backing the 'XXXXDBContext' context has changed since the database was created. Either man ...
- java多线程创建-Thread,Runnable,callable和threadpool
java创建多线程的方式有许多种,这里简要做个梳理 1. 继承Thread类 继承java.lang.Thread类,创建本地多线程的类,重载run()方法,调用Thread的方法启动线程.示例代码如 ...
- ZooKeeper全面介绍
ZooKeeper简介 ZooKeeper是分布式服务框架,主要是用来解决分布式应用中经常遇到的一些数据管理问题,如:统一命名服务.状态同步服务.集群管理.分布式应用配置项的管理等等. ZooKe ...
- Python之re正则模块二
13.编译的标志 可以用re.I.re.M等参数,也可以直接在表达式中添加"?(iLmsux)"标志 *s:单行,“.”匹配包括换行符在内的所有字符 *i:忽略大小写 *L:让&q ...
- 【S】SQL SERVER检查临时表占用空间情况
--检查已标记为需要删除的临时表select * from T_BAS_TEMPORARYTABLENAME; --所有系统创建的临时表及视图SELECT * FROM sys.tables WHER ...