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

排个序就可以了

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<iomanip>
using namespace std;

#define LL long long
const int INF=0x5fffffff;
const double FINF=1e9;
const LL MOD=365*24*60*60;
const int N=100005;
struct node
{
    LL a,b;
}mem[N];
bool cmp(node x,node y)
{
    return x.a*y.b<y.a*x.b;
}
int main()
{
    //freopen("data.txt","r",stdin);
    int n;
    while(cin>>n)
    {
        if(!n)
        break;
        for(int i=0;i<n;++i)
        cin>>mem[i].a>>mem[i].b;
        sort(mem,mem+n,cmp);
        LL ans=0;
        for(int i=0;i<n;++i)
        {
            //cout<<ans*mem[i].b<<endl;
            ans=(ans+mem[i].a+ans*mem[i].b)%MOD;
        }
        cout<<ans<<endl;
    }
    return 0;
}

 

posted on 2012-11-05 16:47  夜->  阅读(183)  评论(0编辑  收藏  举报