http://acm.hdu.edu.cn/showproblem.php?pid=4310

这个题 根据优先级排个序就可以了

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<cmath>
#define LL long long

using namespace std;

const int N=30;
struct node
{
    int H,D;
}mem[N];
bool cmp(node a,node b)
{
    return (a.H*(a.D+b.D)+b.H*b.D)<(b.H*(a.D+b.D)+a.H*a.D);
}
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int sum=0;
        for(int i=0;i<n;++i)
        {
            scanf("%d %d",&mem[i].D,&mem[i].H);
            sum+=mem[i].D;
        }
        sort(mem,mem+n,cmp);
        LL ans=0;
        for(int i=0;i<n;++i)
        {
            ans+=(LL)(sum*mem[i].H);
            sum-=mem[i].D;
        }
        cout<<ans<<endl;
    }
    return 0;
}

  

posted on 2012-07-28 07:52  夜->  阅读(240)  评论(0编辑  收藏  举报