首页 > 其他 > 详细

Hdu4310(贪心)

时间:2014-02-01 14:05:00      阅读:433      评论:0      收藏:0      [点我收藏+]

#include<iostream>
#include<algorithm>
using namespace std;

const int maxn = 20 + 5;

struct Hero {
int hp;
int dps;
}hero[maxn];

int cmp(Hero a, Hero b){
return a.hp * b.dps < b.hp * a.dps ; //比率排序
}

int main(){
int n;
while(cin>>n){
int sum = 0;
for(int i=0; i<n; i++){
cin>>hero[i].dps >> hero[i].hp ;
sum += hero[i].dps ;
}
sort(hero, hero + n, cmp);
int ans = 0;
for(int i=0; i<n; i++){
for(int j=0; j<hero[i].hp; j++){
ans += sum;
}
sum -= hero[i].dps ;
}
cout<<ans<<endl;
}
return 0;
}

Hdu4310(贪心)

原文:http://www.cnblogs.com/cbyniypeu/p/3536956.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!