您的位置:首页 > 编程语言 > Go语言

UVA 11292 Dragon of Loowater

2016-10-21 21:37 417 查看
题解: 贪心.. 恶龙有n个头 有m个猎人

n     m

x(共n行   x表示砍断相应头所需的值)

x

....

x

y(共m行  y表示猎人的砍龙头的能力也是雇佣金的数目)c

y

...

y

排序+贪心(水题)



AC代码:

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cstring>
#include <map>
#include <list>
#include <queue>
using namespace std;
const int maxn=2e5+9;

int d[maxn],loo[maxn];
int main()
{
int n,m;
while(scanf("%d%d",&n,&m))
{
if(n==0&&m==0) break;
for(int i=0; i<n; i++)
scanf("%d",&d[i]);
for(int i=0; i<m; i++)
scanf("%d",&loo[i]);
sort(d,d+n);
sort(loo,loo+m);
int j=0,i,sum=0;
for(i=0; i<n&&j<m;)
{
if(loo[j]>=d[i])
{
i++;
sum+=loo[j];
}
j++;
}
if(i<n) printf("Loowater is doomed!\n");
else printf("%d\n",sum);
}
return 0;
}<strong>
</strong>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: