Problem Description
#include <iostream> #include <algorithm> using namespace std; struct node { double hp; double dps; double bi; } data[25]; bool cmp(const node &a,const node &b) { if(a.bi>b.bi) return true; else if(a.bi==b.bi) { if(a.dps<b.dps) return true; else return false; } else return false; } int main() { int n; double ans; while(cin>>n) { ans=0; for(int i=0;i<n;i++) { cin>>data[i].hp>>data[i].dps; data[i].bi=data[i].dps/data[i].hp*1.0; } sort(data,data+n,cmp); for(int i=0;i<n;i++) { while(data[i].hp) { for(int j=i;j<n;j++) ans+=data[j].dps; data[i].hp--; } } cout<<ans<<endl; } return 0; }
原文:http://www.cnblogs.com/nefu929831238/p/5350134.html