POJ - 3646 The Dragon of Loowater(贪心)
来源:互联网 发布:js下装打什么宝珠 编辑:程序博客网 时间:2024/05/18 01:57
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 numbern of heads that the dragon has, and the number m of knights in the kingdom. The nextn lines each contain an integer, and give the diameters of the dragon's heads, in centimetres. The followingm 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!
题意:一个骑士杀死一条龙,而且骑士的直径大于等于龙的直径长度才可以杀死,然后奖金就是骑士的高度!
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;const int maxn = 20005;int dragon,knights;int dragonnum[maxn];int knightnum[maxn];int main(){ while(scanf("%d%d",&dragon,&knights) == 2 && dragon && knights){ int sum = 0; int inde = 0; for(int i = 0; i < dragon;i++) scanf("%d",&dragonnum[i]); for(int i = 0; i < knights; i++) scanf("%d",&knightnum[i]); if(knights < dragon){ cout<<"Loowater is doomed!"<<endl; continue; }else{ sort(dragonnum,dragonnum+dragon); sort(knightnum,knightnum+knights); int i = 0; for(i = 0; i < dragon;){ while(inde < knights){ if(knightnum[inde] >= dragonnum[i]){ sum+=knightnum[inde]; inde++;i++;break; } inde++; } if(inde == knights)break; } if(i == dragon) cout<<sum<<endl; else{cout<<"Loowater is doomed!"<<endl;} } } return 0;}
- POJ - 3646 The Dragon of Loowater(贪心)
- poj 3646 The Dragon of Loowater 排序+贪心
- POJ-3646-The Dragon of Loowater
- poj 3646 The Dragon of Loowater!水!!
- POJ-3646 The Dragon of Loowater
- POJ 3646 The Dragon of Loowater
- POJ 3646 The Dragon of Loowater G++
- UVa 11292 / POJ 3646 / HDU 1902 Dragon of Loowater (贪心)
- POJ 3646 Dragon of Loowater
- POJ 3646 Dragon of Loowater
- uva11292 The Dragon of Loowater (排序+贪心)
- UVa 11292 The Dragon of Loowater (贪心)
- UVa 11292&HDU1902 The Dragon of Loowater (贪心)
- 文章标题 HDU 1902 :The Dragon of Loowater(贪心)
- HDOJ 1902 The Dragon of Loowater【贪心】
- uva11292 - The Dragon of Loowater (贪心)
- UVa - 11292 - The Dragon of Loowater ( 贪心 )
- HDU 1902 The Dragon of Loowater 贪心
- MX 4 如何连接到Android IDE
- Android中measure过程、WRAP_CONTENT详解以及xml布局文件解析流程浅析(下)
- Uva 1331 - Minimax Triangulation(最优三角剖分 区间DP)
- Request failed: internal server error (500)错误解决
- poj_2299
- POJ - 3646 The Dragon of Loowater(贪心)
- POJO与Java bean 的区别
- Objective-C单例模式
- Struts非Action层获取request
- 欢迎使用CSDN-markdown编辑器
- Matlab Intro - Image Processing
- oracle存储过程
- cout 格式化输出
- C#串口通信 实现打印功能