1.1-1 Dragon of Loowater, Uva 11292

题目:Dragon of Loowater

问题描述:

思路分析:

把骑士能力从高到低排序,如果能砍掉头就用,代码如下

样例代码:

#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 20000+5;
int A[maxn], B[maxn];
int main()
{
    int n, m;
    while(scanf("%d%d", &n, &m) == 2 && m && n)
    {
        int i;
        for(i = 0; i < n; i++)
            scanf("%d", &A[i]);
        for(i = 0; i < m; i++)
            scanf("%d", &B[i]);
        sort(A, A+n);
        sort(B, B+m);
        int cur = 0;    //需要砍掉头的编号
        int cost = 0;   //当前总费用
        for(i = 0; i < m; i++)
        {
            if(B[i] >= A[cur])
            {
                cost += B[i];   //雇佣该骑士
                if(++cur == n)  //如果砍完头,及时退出循环
                    break;
            }
        }
        if(cur < n)
            printf("Loowater is doomed!\n");
        else
            printf("%d\n", cost);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/DreamInPal/p/10851947.html

时间: 2024-08-30 05:35:29

1.1-1 Dragon of Loowater, Uva 11292的相关文章

UVA 11292 Dragon of Loowater(简单贪心)

Problem C: The Dragon of Loowater 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 predato

·UVa」 11292 - Dragon of Loowater( 贪心 )

Problem C: The Dragon of Loowater 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 predato

UVA它11292 - Dragon of Loowater

Problem C: The Dragon of Loowater 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 predato

UVA 题目11292 Dragon of Loowater

Problem C: The Dragon of Loowater 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 predato

[2016-03-14][UVA][11292][Dragon of Loowater]

时间:2016-03-14 19:50:12 星期一 题目编号:[2016-03-14][UVA][11292][Dragon of Loowater] 题目大意: 有m个骑士要砍n条龙,每个骑士能看掉龙的头颅当且仅当其实的能力值大于龙的头的直径,每个其实砍掉一条龙需要付出数值上等于能力值的代价,问m个骑士能否砍完所有龙,能则输出最小代价,否则输出"Loowater is doomed!" 输入: 多组数据 每组数据 n m n行 龙头的直径 m行 骑士的能力值 输出: 如果能砍完所有

UVA之11292 Dragon of Loowater

Problem C: The Dragon of Loowater 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 predato

UVa 11292 Dragon of Loowater

1 /*UVa 11292 Dragon of Loowater*/ 2 #include<iostream> 3 #include<cstdio> 4 #include<cmath> 5 #include<algorithm> 6 using namespace std; 7 int n,m; 8 int main(){ 9 while(scanf("%d%d",&n,&m) && n!=0 &&

[UVA] 11292 - Dragon of Loowater [贪心+队列]

Problem C: The Dragon of Loowater Time limit: 1.000 seconds 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.

【UVA11292】Dragon of Loowater

C - Dragon of Loowater Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 11292 Appoint description:  System Crawler  (2015-07-27) Description Problem C: The Dragon of Loowater Once upon a time, in the K