uva11292 Dragon of Loowater

水题,排序遍历即可

#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

const int maxn = 20010;
int drag[maxn], kn[maxn];
int main()
{
    int n, m, cost;
    while (cin >> n >> m) {
        if(n == 0 && m == 0)break;
        for (int i = 0;i < n;i++)cin >> drag[i];
        for (int i = 0;i < m;i++)cin >> kn[i];
        sort(drag, drag + n);
        sort(kn, kn + m);
        int cur = 0;
        cost = 0;
        for (int i = 0;i < m;i++) {
            if (kn[i] >= drag[cur]) {
                cost += kn[i];
                if (++cur == n)break;
            }
        }
        if (cur < n)cout << "Loowater is doomed!" << endl;
        else cout << cost << endl;
    }
    return 0;
}
时间: 2024-12-19 16:29:32

uva11292 Dragon of Loowater的相关文章

[UVA-11292] Dragon of Loowater(勇者斗恶龙) 题解

此文为博主原创题解,转载时请通知博主,并把原文链接放在正文醒目位置. 题目链接:(vjudge)https://vjudge.net/problem/UVA-11292 Uva上找了半天愣是没找到Problem在哪...vjudge大法好. 题目大意: 有n条龙和m个骑士,每条龙有一个邪恶值z,每个骑士有一个能力值x.如果骑士的能力值大于龙的邪恶值,骑士可以杀死龙,但同时需要支付x枚金币. 给出龙和骑士的数据,问要杀死所有的龙,最少需要支出多少金币.每个骑士只能雇用一次. 输入包含多组数据,以

UVA11292 HDU1902 POJ3646 Dragon of Loowater

问题链接:UVA11292 HDU1902 POJ3646 Dragon of Loowater. 这个问题是一个典型的贪心法问题,求代价最小. 由于需要用到排序函数,C++的排序函数参数比较简单,所以用C++编程. AC通过的C++语言程序如下: /* UVA11292 HDU1902 POJ3646 Dragon of Loowater */ #include <cstdio> #include <algorithm> using namespace std; #define

【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

uva-----11292 The 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 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