UVA 11292 水题

n个恶龙,m个勇士。只有当勇士的能力值大于等于恶龙的时候才能斩杀他,并且雇佣一定能力值的勇士需要一定的费用。问,如何用最小的费用来雇佣勇士,并且能杀完龙,如果不能就输出loowater...


sort一下暴力就好了



#include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int maxn = 20000 + 5; int n, m; int k[maxn], foe[maxn]; int main(){ while (scanf("%d %d", &n, &m) && n + m){ memset(k, 0, sizeof(k)); memset(foe, 0, sizeof(foe)); for (int i = 0; i < n; i++){ scanf("%d", foe + i); } for (int i = 0; i < m; i++){ scanf("%d", k + i); } sort(k, k + m); sort(foe, foe + n); int cnt = 0; bool vis[maxn]; memset(vis, 0, sizeof(vis)); for (int i = 0; i < n; i++){ bool flag = 0; for (int j = 0; j < m; j++){ if (vis[j]) continue; if (k[j] >= foe[i]){ flag = 1; cnt += k[j]; vis[j] = 1; break; } } if (flag == 0) { cnt = -1; break; } } if (cnt == -1){ printf("Loowater is doomed!\n"); } else printf("%d\n", cnt); } return 0; } </cstring></algorithm></cstdio>

你可能感兴趣的:(UVA 11292 水题)