标签:
uva11292 Dragon of Loowater
链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=456&problem=2267&mosmsg=Submission+received+with+ID+16086958
题意:找勇者杀龙,龙有多个头,每个头能力不一,众勇者能力不一,能力与佣金相等。用最少的钱杀死龙
题解:很简单的题目,用贪心算法找勇者即可。
代码:
#include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> using namespace std; const int MAXN=20000+1000; int a[MAXN],b[MAXN],vis[MAXN]; int main() { int n,m; while(cin>>n>>m&&(n+m)){ memset(vis,0,sizeof(vis)); for(int i=0;i<n;i++) cin>>a[i]; for(int j=0;j<m;j++) cin>>b[j]; sort(a,a+n); sort(b,b+m); int sum=0; int ok=1; for(int i=0;i<n;i++) { int flag=0; int j; for(j=0;j<m;j++) { if(b[j]>=a[i]&&!vis[j]) { flag=1;break; } } if(flag) { vis[j]=1; sum+=b[j]; } else { ok=0; break; } } if(ok) cout<<sum<<endl; else cout<<"Loowater is doomed!\n"; } return 0; }
标签:
原文地址:http://www.cnblogs.com/diang/p/4802960.html