uva 11292 Dragon of Loowater (简单贪心)
2020-06-06 07:37
423 查看
题意: 有m个骑士,n头的龙,一个能力值为x的骑士可以砍掉恶龙一个直径不超过x的头,且需要支付x的金币,一个人只能砍一个头,求砍掉龙的所有头支付最少的金币。无解输出 “Loowater is doomed!”。
解法: 先把龙头的直径和勇士的能力按从小到大排序,之后按顺序将龙头的直径和骑士的能力比较,能力大于半径,支付金币,当龙头被砍完了就结束比较,输出结果.
#include<cstdio> #include<algorithm> using namespace std; int dia[20009]; //记录龙的直径 int kni[20009]; //记录骑士的能力 int main() { int n,m; //n是龙头的个数,m是骑士的个数 while(scanf("%d%d",&n,&m)!=EOF) { if(n == 0 && m == 0)break; for(int i=1;i <= n;i++) { scanf("%d",&dia[i]); } for(int i=1;i <= m;i++) { scanf("%d",&kni[i]); } sort(dia + 1,dia + 1 + n); sort(kni + 1,kni + 1 + m); int cost = 0; int i=1; for(int k=1;k <= m;k++) { if(dia[i] <= kni[k]) { cost += kni[k]; if(++i > n)break; //当龙头砍完时退出循环 } } if(n < i) printf("%d\n",cost); else printf("Loowater is doomed!\n"); } return 0; }
相关文章推荐
- UVA 11292 Dragon of Loowater(简单贪心)
- The Dragon of Loowater UVa 11292(排序后贪心)
- Uva11292--------------(The Dragon of Loowater)勇者斗恶龙 (排序后贪心)
- UVA 11292 Dragon of Loowater(贪心)
- UVa 11292 - Dragon of Loowater(排序贪心)
- |UVA 11292|贪心|Dragon of Loowater
- UVa 11292 - Dragon of Loowater[贪心]
- uva - 11292 - Dragon of Loowater(贪心)
- uva11292 - The Dragon of Loowater (贪心)
- UVa-11292 - Dragon of Loowater:简单题
- uva 11292 - Dragon of Loowater(贪心)
- UVa Dragon of Loowater 11292 (贪心)
- UVa 11292 The Dragon of Loowater (贪心)
- [ACM_水题] UVA 11292 Dragon of Loowater [勇士斗恶龙 双数组排序 贪心]
- 贪心/思维题 UVA 11292 The Dragon of Loowater
- UVaThe Dragon of Loowater-11292(排序+贪心)
- Uva 11292 Dragon of Loowater (贪心)
- UVa 11292 - Dragon of Loowater(贪心)
- UVA 11292 DRAGON OF LOOWATER 【贪心】
- UVA - 11292 Dragon of Loowater 贪心