Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

实在没办法了···超时了5次···re了6次····各位帮忙看看···(c代码)···

Posted by lgl0927 at 2010-08-04 23:52:42 on Problem 2510
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int comp(const void *, const void *);
main()
{
    char str[100][20];
    int i,j,k,r1,r2,count1=0,count2=0,flag;
    __int64 tim[100];
    float sum[1000000];

    struct
    {
        __int64  tf;
        float quaf;
    }co[100];
    struct
    {
        __int64 tl;
        float qual;
    }cl[100];

    memset(sum,0,sizeof(sum));

    i=0;
    while(scanf("%s",str[i])!=EOF)
    {

        if(str[i][0]=='Q')
        {
            scanf("%I64d",&tim[i]);
            i++;
        }

        if(strcmp(str[i],"Chocolate")==0)
        {
            scanf("%I64d%f",&cl[count1].tl,&cl[count1].qual);
            count1++;
        }
        if(strcmp(str[i],"Coffee")==0)
        {
            scanf("%I64d%f",&co[count2].tf,&co[count2].quaf);
            count2++;
        }
    }

    for(j=0;j<i;j++)
    {
        r1=r2=0;
        flag=0;
        for(k=0;k<j;k++)
        {
            if(tim[j]==tim[k])
            {
                flag=1;
                sum[tim[j]]=sum[tim[k]];
            }
        }
        if(flag==0)
        {
            while(tim[j]>=co[r1].tf && r1<count2)
            {
                if(2.0*co[r1].quaf-1.0*(tim[j]-co[r1].tf)*(tim[j]-co[r1].tf)/79.0>0)
                {
                    sum[tim[j]]+=2.0*co[r1].quaf-1.0*(tim[j]-co[r1].tf)*(tim[j]-co[r1].tf)/79.0;
                }
                r1++;
            }
            while(tim[j]>=cl[r2].tl && r2<count1)
            {
                if(8.0*cl[r2].qual-1.0*(tim[j]-cl[r2].tl)/12.0>0)
                {
                    sum[tim[j]]+=8.0*cl[r2].qual-1.0*(tim[j]-cl[r2].tl)/12.0;
                }
                r2++;
            }
        }
    }

    qsort(tim,i,sizeof(__int64),comp);
    for(j=0;j<i;j++)
    {
        if(sum[tim[j]]<1)
            printf("%I64d 1.0\n",tim[j]);
        else
            printf("%I64d %.1f\n",tim[j],sum[tim[j]]);
    }
}
int comp(const void *p, const void *q)
{
     return (*(__int64 *)p - *(__int64 *)q);
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator