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>
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>
相关文章推荐
- [UVA] 11292 - Dragon of Loowater
- UVa 11292 Dragon of Loowater
- UVa 11292 - Dragon of Loowater
- uva 11292 The Dragon of Loowater
- UVA 11292 - Dragon of Loowater
- UVA 11292 Dragon of Loowater
- uva11292-Dragon of Loowater
- UVa 11292:Dragon of Loowater(水题)
- UVa 11292 Dragon of Loowater
- UVa11292 - Dragon of Loowater
- UVA 11292(HDU 1902)The Dragon of Loowater
- UVA 11292 The Dragon of Loowater
- Uva 11292 Dragon of Loowater
- Uva 11292 The Dragon of Loowater 模拟题
- UVA 11292 - Dragon of Loowater
- Uva 11292 The Dragon of Loowater
- UVa11292 The Dragon of Loowater(sort排序直接比较)
- uva 11292 - Dragon of Loowater
- UVA 11292 - Dragon of Loowater
- UVA11292 Dragon of Loowater