标签:pre == scanf else ble 大于 付出 uva 遍历
题目链接:https://vjudge.net/problem/UVA-11292
题目大意:有一个多头怪,需要击败。多头怪有n个头,每一个头有不同的直径,有m个勇士,每个勇士有一个能力值,
能力值大于直径就能砍掉那个头,但需要付出等同于能力值的金币,每个勇士只能砍一个头,问最少用多少金币可以杀
掉多头怪。如果无法杀死,输出“Loowater is doomed!”
题目思路:将直径和能力从小到大排序,遍历能力值,对于当前能力值如果能砍,就雇佣,否则不雇佣
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 20005;
int abty[maxn];
int length[maxn];
int main()
{
int n, m;
while(~scanf("%d%d",&n,&m))
{
if(n == 0 && m == 0) break;
for(int i = 1; i <= n; i ++) scanf("%d",&length[i]);
for(int i = 1; i <= m; i ++) scanf("%d",&abty[i]);
sort(length + 1, length + n + 1);
sort(abty + 1, abty + m + 1);
int sum = 0;
int pos = 1;
for(int i = 1; i <= m; i ++)
{
if(abty[i] >= length[pos])
{
sum += abty[i];
pos++;
if(pos == n + 1) break;
}
}
if(pos <= n) printf("Loowater is doomed!\n");
else printf("%d\n",sum);
}
return 0;
}
标签:pre == scanf else ble 大于 付出 uva 遍历
原文地址:https://www.cnblogs.com/goxy/p/9630930.html