UVA它11292 - Dragon of Loowater
Problem C: The Dragon of Loowater
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 Specification:
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 Specification:
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
Output for Sample Input:
11
Loowater is doomed!
- /*********************************
- * 日期:2013-4-19
- * 作者:SJF0115
- * 题号: 题目11292 - Dragon of Loowater
- * 来源:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2267
- * 结果:AC
- * 来源:UVA
- * 总结:
- **********************************/
- #include<stdio.h>
- #include<stdlib.h>
- int Dragon[20001],Knights[20001];
- //排序函数
- int cmp(const void *a,const void *b){
- return *(int *)a - *(int *)b;
- }
- int main ()
- {
- int i,j,N,M,cost,index;
- //freopen("C:\\Users\\XIAOSI\\Desktop\\acm.txt","r",stdin);
- while(scanf("%d %d",&N,&M) != EOF){
- if(N == 0 && M == 0){
- break;
- }
- //金币
- cost = 0;
- index = 0;
- //头
- for(i = 0;i < N;i++){
- scanf("%d",&Dragon[i]);
- }
- //勇士
- for(i = 0;i < M;i++){
- scanf("%d",&Knights[i]);
- }
- //排序
- qsort(Dragon,N,sizeof(int),cmp);
- qsort(Knights,M,sizeof(int),cmp);
- //贪心
- for(i = 0;i < M;i++){
- if(index >= N){
- break;
- }
- if(Knights[i] >= Dragon[index]){
- //统计所花金币
- cost += Knights[i];
- index++;
- }
- }
- //输出
- if(index >= N){
- printf("%d\n",cost);
- }
- else{
- printf("Loowater is doomed!\n");
- }
- }
- return 0;
- }
版权声明:本文博客原创文章,博客,未经同意,不得转载。
UVA它11292 - Dragon of Loowater的更多相关文章
- 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 Dragon of Loowater (勇者斗恶龙)
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- [ACM_水题] UVA 11292 Dragon of Loowater [勇士斗恶龙 双数组排序 贪心]
Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shor ...
- UVa 11292 - Dragon of Loowater(排序贪心)
Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem.The shore ...
- UVa 11292 Dragon of Loowater
简单贪心 龙头的直径和人的佣金排序,价值小的人和直径小的配 #include<iostream> #include<cstdio> #include<cmath> ...
- UVA - 11292 Dragon of Loowater 贪心
贪心策略:一个直径为X的头颅,应该让雇佣费用满足大于等于X且最小的骑士来砍掉,这样才能使得花费最少. AC代码 #include <cstdio> #include <cmath&g ...
- UVa 11292 Dragon of Loowater (水题,排序)
题意:有n个条龙,在雇佣勇士去杀,每个勇士能力值为x,只能杀死头的直径y小于或等于自己能力值的龙,只能被雇佣一次,并且你要给x赏金,求最少的赏金. 析:很简单么,很明显,能力值高的杀直径大的,低的杀直 ...
- 贪心/思维题 UVA 11292 The Dragon of Loowater
题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...
- The Dragon of Loowater
The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into ...
随机推荐
- UITabbar的常用属性
// //设置tabbar的背景颜色 // [self.tabBar setBarTintColor:[UIColor redColor]]; // //设置选中时图片和文字的颜色 // [self. ...
- Ural 1297 Palindrome 【最长回文子串】
最长回文子串 相关资料: 1.暴力法 2.动态规划 3.中心扩展 4.Manacher法 http://blog.csdn.net/ywhorizen/article/details/6629268 ...
- Ural 1313 - Some Words about Sport
Ural doctors worry about the health of their youth very much. Special investigations showed that a l ...
- json_response的用法
传统的方法是当我们处理一个表单时,我们Post数据给服务器,服务器对数据进行处理后将数据返回给用户,此时部分写法是用页面刷新的方式将页面重新刷新一次呈现给用户,这样的话用户相当于读入了两次页面,人一多 ...
- OKR 方法 学习笔记
最近公司兴起了对OKR这个词的讨论,并且听到时总会伴随提到KPI,提到绩效考核.那OKR到底是什么呢?与KPI的区别在哪里?与绩效考核有什么关系?它与我们现在推行的敏捷开发有啥关系呢?因此,就到网上查 ...
- 基于visual Studio2013解决C语言竞赛题之0605strcat
题目
- Python字典处理技巧
从字典中取值(不想由于搜索的键不存在而异常) 解决方法: 使用字典的get方法 (get方法只读取字典的值而不会去修改字典) d={'key':'value'} print d.get('key',' ...
- Entity Framework基金会
概要 Entity Framework缩写EF,微软ORM产品. 本篇博客将简单的介绍它,至于它的详细深层次的使用,大家能够查询对应的操作手冊,该篇不过入门. Entity Framework和Lin ...
- cocos2dx 3.0 飞机大战
因为课程须要.然后又水平有限.所以写了个飞机大战.加上不会画画.所以图片资源也是从微信apk解压出来的,设计思路參考的偶尔e网事. 闲话不说.先讲一下设计.大体上一共分为3个场景.场景以下是Layer ...
- 在eclipse上安装 sdk出现的各种问题
在eclipse上下进行android开发需要 有android SDK 和ADT 一般adt版本瑶台低, 会被提示安装较高版本的ADT, 不然, SDK可能无法使用 在安装 SDK过程中出现这样 ...