题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4310
题记:按照dps/hp来排序即可。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
double hp;
double dps;
};
bool cmp(node a,node b){
return a.dps/a.hp>b.dps/b.hp;
}
int main(){
int n;
while(cin>>n){
node node[25];
ll sum=0,ans=0;
for(int i=0;i<n;i++){
cin>>node[i].dps>>node[i].hp;
sum+=node[i].dps;
}
sort(node,node+n,cmp);
for(int i=0;i<n;i++){
ans+=node[i].hp*sum;
sum-=node[i].dps;
}
cout<<ans<<endl;
}
return 0;
}