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

一次过了。。。。。。。。。。。难得啊

Posted by yangyangyang91 at 2011-08-05 19:50:35 on Problem 1018
#include <stdio.h>
#include <iostream>
#include <string.h>
#define M 10000
using namespace std;

int f[101][M];
bool hash[M];

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        int b,p;
        int max=0;
        scanf("%d",&n);

        memset(f,1000000,sizeof(f));
        memset(hash,false,sizeof(hash));
        for(int i=0;i<M;i++)
        f[0][i]=0;

        for(int i=1;i<=n;i++)
        {
            scanf("%d",&m);
            for(int j=0;j<m;j++)
            {
                scanf("%d%d",&b,&p);
                hash[b]=true;
                if(max<b)max=b;

                for(int k=b;k<M;k++)
                f[i][b]=(f[i-1][k]+p)<f[i][b]?(f[i-1][k]+p):f[i][b];

                for(int k=0;k<b;k++)
                if(f[i-1][k]+p<f[i][k])f[i][k]=f[i-1][k]+p;

            }
        }

        float ans=0;
        for(int i=1;i<=max;i++)
        if(f[n][i]>0&&hash[i]&&i/(float)f[n][i]>ans)ans=i/(float)f[n][i];

        printf("%.3f\n",ans);
    }
}

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