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

样例过了。。。但是WA,求大牛看看是不是算法不对

Posted by hl520 at 2011-04-15 23:53:43 on Problem 1018
数组dpmax是记录每输入一组设备后得到的最优解,
#include<iostream>
#include<stdio.h>
using namespace std;
typedef struct bandwidth_price
{
    int bandwidth,price;
}bp ;
bp dp[110],dpmax[110];
int main()
{
    int t,n,m,i,j,bw,pr;
    double bpmax;
    scanf("%d",&t);
    while(t--)
    {
        for(i=0;i<110;i++)
        {
            dpmax[i].bandwidth=0;
            dpmax[i].price=0;
        }
        scanf("%d",&n);
        while(n--)
        {
            scanf("%d",&m);
            for(i=0;i<m;i++)
            {
                scanf("%d %d",&(dp[i].bandwidth),&(dp[i].price));
            }
            for(i=0;i<m;i++)
            {
                bpmax=0.0;bw=pr=0;
                for(j=0;dpmax[j].bandwidth!=0;j++)
                {
                    int a,b;
                    a=dpmax[j].bandwidth>dp[i].bandwidth?dp[i].bandwidth:dpmax[j].bandwidth;
                    b=dpmax[j].price+dp[i].price;
                    if(a/(b*1.0)>bpmax)
                    {
                        bpmax=a/(b*1.0);
                        bw=a;
                        pr=b;
                    }
                }
                if(bw!=0)
                {dp[i].bandwidth=bw;
                dp[i].price=pr;}
            }
                for(i=0;i<m;i++)
                {
                    dpmax[i].bandwidth=dp[i].bandwidth;
                    dpmax[i].price=dp[i].price;
                }
        }
        bpmax=0.0;
        for(i=0;i<m;i++)
        {
            if(dpmax[i].bandwidth/(dpmax[i].price*1.0)>bpmax)
            {
                bpmax=dpmax[i].bandwidth/(dpmax[i].price*1.0);
            }
        }
        printf("%.3f\n",bpmax);
    }return 0;
}

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