首页 > 代码库 > BZOJ 1634 护花

BZOJ 1634 护花

d/t从大到小排序。

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#define maxn 100500using namespace std;long long n,ans=0;struct pnt{    long long d,t,id;}p[maxn];bool cmp(pnt x,pnt y){    return (double)x.d/x.t>(double)y.d/y.t;}int main(){    scanf("%lld",&n);    for (long long i=1;i<=n;i++)    {        scanf("%lld%lld",&p[i].t,&p[i].d);        p[i].id=i;    }        sort(p+1,p+n+1,cmp);    long long t=0;    for (long long i=1;i<=n;i++)    {        ans+=t*p[i].d;        t+=2*p[i].t;    }    printf("%lld\n",ans);    return 0;}

 

BZOJ 1634 护花