UVA 11292 Dragon of Loowater
来源:互联网 发布:数据提供商 编辑:程序博客网 时间:2024/06/13 23:24
分析
虽然屠龙的勇士极其勇敢,但是这题难度并不高。
斩杀n头龙并没有指定从哪一个头开始,也没有指定从哪一个勇士开始。那么斩头的策略应该是由小及大,这样,可以让勇士由小及大的斩杀,遍历所有的勇士,斩尽其能斩之头,终得如下代码。
代码
#include <cstdio>#include <algorithm>#define MAX 20005using std::sort;int H[MAX], C[MAX];int N, M;void solve(){ sort(H, H+N); sort(C, C+M); int coins = 0; for (int i = 0, j = 0; i < M; i++) if (C[i] >= H[j]) { coins += C[i]; j++; if (j == N) { printf("%d\n", coins); return; } } printf("Loowater is doomed!\n"); return;}int main(){ while (scanf("%d%d", &N, &M), (N+M)) { for (int i = 0; i < N; i++) scanf("%d", &H[i]); for (int i = 0; i < M; i++) scanf("%d", &C[i]); solve(); } return 0;}
题目
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 3547842 155100 0
Sample Output
11Loowater is doomed!
- uva --11292 --Dragon of Loowater
- UVa 11292 - Dragon of Loowater
- uva - 11292 - Dragon of Loowater
- UVA 11292 - Dragon of Loowater
- uva 11292 - Dragon of Loowater
- Uva-11292-Dragon of Loowater
- UVA 11292 - Dragon of Loowater
- UVA 11292 Dragon of Loowater
- uva 11292 - Dragon of Loowater
- UVA 11292 - Dragon of Loowater
- UVA 11292 Dragon of Loowater
- UVA 11292 Dragon of Loowater
- UVa 11292 Dragon of Loowater
- UVa 11292 Dragon of Loowater
- UVA 11292 Dragon of Loowater
- uva 11292 Dragon of Loowater
- UVA - 11292 Dragon of Loowater
- UVa 11292 Dragon of Loowater
- Android开发环境的配置(Ubuntu 14.04 64位)
- codeforces gym 100342F Move to Front
- pl统计小程序a
- 浅析UIWebView编程
- 9.Python基础 面向对象的进一步拓展
- UVA 11292 Dragon of Loowater
- 李泽影的第一篇博客
- LA 5092 && hdu 3723 Delta Wave (卡特兰数)
- mac android studio NDK 安装使用(不用翻墙)
- 我只是一个卖煎饼果子的,你跟我谈个鸡毛营销战略,这么牛B自己敲钟去啊 ...
- android学习笔记(7)AbsoluteLayout+FrameLayout+RelativeLayout+TableLayout四大布局方式
- Antlr v4入门教程和实例 - 西代零零发 - 博客频道 - CSDN.NET
- Quick-Select 1亿个数快速求第K小的数 分治法
- 内存溢出的问题:Run-Time Check Failure #2 - Stack around the variable 'trans' was corrupted.解决方案