现在的位置: 首页 > 综合 > 正文

hdu4442

2013年10月07日 ⁄ 综合 ⁄ 共 699字 ⁄ 字号 评论关闭

/*
分析:
    贪心(2012金华现场赛A题)。
    假设已经排了t时间了,现在有两个队列,a1、a2、b1、b2。
先排队列1:ans1=t+(a2*t+a1+b1*b2*(a1+t));
先排队列2:ans2=t+(b2*t+b1+a1+a2*(b1+t))。
    化简后,只剩下了b2*a1和a2*b1,那么按照这个,对每两个进行
排序,就行了。

                                                             2012-10-30
*/

#include"stdio.h"
#include"string.h"
#include"stdlib.h"
struct A
{
    __int64 a,b;
}E[100011];
int cmp(const void *a,const void *b)
{
    struct A *c,*d;
    c=(struct A *)a;
    d=(struct A *)b;
    __int64 t1,t2;
    t1=(c->a)*(d->b);
    t2=(d->a)*(c->b);
    if(t1>t2)   return 1;
    else        return -1;
}
int main()
{
    int n;
    int i,l;
    int temp;
    __int64 ans;
    while(scanf("%d",&n),n)
    {
        for(i=0;i<n;i++)    scanf("%I64d%I64d",&E[i].a,&E[i].b);
        qsort(E,n,sizeof(E[0]),cmp);

        ans=0;
        temp=365*24*60*60;
        for(i=0;i<n;i++)    {ans+=E[i].a+ans*E[i].b;ans%=temp;}
        printf("%I64d\n",ans);
    }
    return 0;
}

抱歉!评论已关闭.