POJ-3646 The Dragon of Loowater
来源:互联网 发布:侠客风云传前传 mac 编辑:程序博客网 时间:2024/06/06 12:30
描述
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!
输入
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
输出
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!
样例输入
2 3547842 155100 0
样例输出
11Loowater is doomed!
解析: 贪心,将头的大小,骑士的能力排序,从小向大找,能砍则要,并加上cost,否则继续向后找。
代码:
#include<stdio.h>#include<algorithm>using namespace std;bool cmp(int a,int b){return a<b;}int main(){int n,m,i,j,num;int a[20001],b[20001];while(scanf("%d%d",&n,&m),n||m){num=0;for(i=0;i<n;i++)scanf("%d",&a[i]);for(i=0;i<m;i++)scanf("%d",&b[i]);sort(a,a+n,cmp);sort(b,b+m,cmp);int ans=0;for(i=0;i<m;i++){if(num>=n)break; if(b[i]>=a[num]) { ans+=b[i]; num++; } }if(num>=n)printf("%d\n",ans);else printf("Loowater is doomed!\n");}}
- 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++
- POJ 3646 Dragon of Loowater
- POJ 3646 Dragon of Loowater
- 白皮书:The Dragon of Loowater, UVa 11292,POJ 3646
- poj 3646 The Dragon of Loowater 排序+贪心
- POJ - 3646 The Dragon of Loowater(贪心)
- 周赛 POJ 3546 The Dragon of Loowater
- The Dragon of Loowater
- The Dragon of Loowater
- The Dragon of Loowater
- The Dragon of Loowater
- The Dragon of Loowater
- The Dragon of Loowater
- UVA11292 The Dragon of Loowater
- c++程序设计——实验4
- bananapi 设置AV输出
- MFC - CTreeCtrl操作
- HDOJ 5229 ZCC loves strings
- 第五个人多大
- POJ-3646 The Dragon of Loowater
- ecshop促销剩余时间 的函数调用方法
- Vlc播放rtsp视频
- MIT算法导论——第七讲.哈希表
- c++程序设计——实验3
- Maximum Gap
- 10个帮程序员减压放松的网站!
- 黑马程序员--学习日志4--JAVA循环体语句和控制跳转语句
- Leetcode Happy Number