UVaThe Dragon of Loowater-11292(排序+贪心)
来源:互联网 发布:网上购物商城源码ssh 编辑:程序博客网 时间:2024/05/01 21:43
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 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 last test case is followed by a line containing:
0 0
Loowater is doomed!
2 3547842 155100 0
11Loowater is doomed!
//思路:对A,B分别排序,再贪心选择(能力强的knights就去chop off直径大的头)
AC源码:
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;const int maxn=20000+10;int A[maxn],B[maxn];int main(){int n,m;while(scanf("%d %d",&n,&m)&&n){for(int i=0;i<n;++i)scanf("%d",&A[i]);for(int i=0;i<m;++i)scanf("%d",&B[i]);sort(A,A+n);sort(B,B+m);int cur=0;int cost=0;for(int i=0;i<m;++i){if(B[i]>=A[cur]){cost+=B[i];if(++cur==n)break;}}if(cur==n)printf("%d\n",cost);elseprintf("Loowater is doomed!\n");}return 0;}
阅读全文
0 0
- UVaThe Dragon of Loowater-11292(排序+贪心)
- UVa 11292 - Dragon of Loowater(排序贪心)
- UVa - 11292 - Dragon of Loowater ( 排序 + 贪心 )
- UVa 11292 Dragon of Loowater 贪心+排序
- UVa 11292 Dragon of Loowater(排序+贪心)
- The Dragon of Loowater UVa 11292(排序后贪心)
- UVA 11292 Dragon of Loowater(贪心+排序)
- 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 【贪心】
- 11292 - Dragon of Loowater(贪心)
- UVa Dragon of Loowater 11292 (贪心)
- UVa - 11292 - The Dragon of Loowater ( 贪心 )
- UVA 11292 Dragon of Loowater(贪心)
- 整数转换成罗马数字 python
- bzoj 1045: [HAOI2008]糖果传递
- zookeeper的简单使用
- 剑指offer——平衡二叉树
- 剑指Offer----替换空格
- UVaThe Dragon of Loowater-11292(排序+贪心)
- Maven的配置文件pom.xml
- 二值图像腐蚀与膨胀操作样例
- bzoj1856: [Scoi2010]字符串
- 身体训练
- 剑指offer:字符串的排列
- epoll讲解
- React Native自定义控件【底部抽屉菜单】
- Eclipse中10个最有用的快捷键组合