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 ...
随机推荐
- defer与async
defer:该属性指定的脚本不会修改DOM,因此代码可以安全的延迟执行. 含defer属性的script标签可以放在任何位置,在页面解析到该script标签时,开始下载脚本,但不会执行脚本,直至DOM ...
- Java面试常会被问到的经典面试题,学习或者求职,你都要好好掌握
Java现在的热度虽然有所下降,但是,学Java的人依旧很多..Java的岗位也是渗透很多.那么,那些经典的Java知识点,你能看到问题就能说出一二三吗?来一起看看.. 1.JDK和JRE的区别 2. ...
- Django中请求的生命周期
1. 概述 首先我们知道HTTP请求及服务端响应中传输的所有数据都是字符串. 在Django中,当我们访问一个的url时,会通过路由匹配进入相应的html网页中. Django的请求生命周期是指当用户 ...
- SQL2012导出的脚本没有if exists判断
SQL2012导出的脚本没有if exists判断 以前用SQL2000的时候,导出存储过程,表各种object的时候,前面会自动加if exists的一段脚本,这样的脚本很方便的可以重复执行.现在使 ...
- 重写Fields 控制models 数据输出字段
models: public function Fields() { $fields = parent::Fields();//原来models输出字段 $fields['parentComment' ...
- android 开源收藏
第一部分 个性化控件(View) 主要介绍那些不错个性化的View,包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.Pro ...
- Python学习笔记 set&&dict
dict 是个好东西啊,这个东东是类似于c++里面的map.其形式为 dict={key:value,key:value....} 这个东西好玩的地方主要在于 1.他的key值查找采用的是哈希算法,速 ...
- 中文编程语言之Z语言初尝试: ZLOGO 4
原文: https://zhuanlan.zhihu.com/p/31505895. 作者为本人. @TKT2016 开发的Z语言(ZLOGO是它的一个部分)是本人至今看到的唯一一个仍活跃开发的开源且 ...
- 深入讲解HashMap原理
1. HashMap概述: HashMap是基于哈希表的Map接口的非同步实现.此实现提供所有可选的映射操作,并允许使用null值和null键.此类不保证映射的顺序,特别是它不保证该顺序恒久不变 ...
- Android7.0 PowerManagerService 之亮灭屏(一)
本篇从按下power按键后,按键事件从InputManagerService 传到PhoneWindowManager.java开始分析power 按键做屏幕亮灭过程的分析,关于power 按键的其他 ...