hdu4310 贪心
考虑每次血口的要少 就按照一滴血多少伤害来计算。由于直接相除有小数。考虑x/y > a/b => x*b >y*a;
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct node { int hp; int dps; }a[25]; bool cmp(node a,node b) { return a.dps*b.hp>a.hp*b.dps; } int main() { int i,j,n; int sum; while(scanf("%d",&n)!=EOF) { sum=0; for(i=0;i<n;i++) { scanf("%d%d",&a[i].dps,&a[i].hp); sum+=a[i].dps; } sort(a,a+n,cmp); int all=0; for(i=0;i<n;i++) { all+=sum*a[i].hp; sum-=a[i].dps; } printf("%d\n",all); } }