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;
}



原文地址:https://www.cnblogs.com/zjutzz/p/3207889.html