UVA11292

题意:有n个恶龙,有m个骑士可雇佣,每个骑士能力为x,表示可以砍掉恶龙的不超过x的头,且雇佣他需要x金币。要求砍掉恶龙所有的头且付金币最少。
类型:排序+模拟
代码:

#include
#include
#include
using namespace std;
const int maxn = 20000+5;
int A[maxn];
int B[maxn];
int main(){
//    freopen("in.txt", "r", stdin);
    int n, m;
    while(scanf("%d%d", &n, &m)!=EOF && (m||n)){
        int i;
        for(i=0; i
            scanf("%d", &A[i]);
        for(i=0; i
            scanf("%d", &B[i]);
        sort(A, A+n);
        sort(B, B+m);
        int cur = 0;
        int cost = 0;
        for(i=0; 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;
}
时间: 2024-09-20 00:22:13

UVA11292的相关文章

uva11292 - Dragon of Loowater

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2267 将骑士和龙头都按升序排序,按顺序如果骑士值大于所有龙头则可以继续,如果可以杀掉所有龙头则输出骑士和否则不行. #include<iostream> #include<cstdio> #include<cstring> #include<algo