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 zyz at 2007-05-12 16:36:13 on Problem 2744
In Reply To:疯了,TLE??怎么可能?我本地运行很快的. Posted by:zyz at 2007-05-12 16:34:22
/*#include<iostream>
#include<iomanip>
using namespace std;
*/
#include<stdio.h>

int xx[102];

double tt[110][110];

int r;
double b, v, e, f;

double time(int x){
    if(x>=r)
        return 1/(v-e*(x-r));
    else
        return 1/(v-f*(r-x));
}

double run(int st, int ed){
    int xi, x, i;
    if(tt[st+1][ed+1])
        return tt[st+1][ed+1];
    double min=0.0;
    if(st==-1) xi=0;
    else {xi=xx[st];min+=b;}
    for(x=xi;x<xx[ed];x++){
        min += time(x-xi);
    }
    if(st+1==ed){
        tt[st+1][ed+1]=min;
        return min;
    }
    for(i=st+1;i<ed;i++){
        double tmp=run(st, i)+run(i, ed);
        if(min>tmp)
            min=tmp;
    }
    tt[st+1][ed+1]=min;
    return min;
}

int main(){
    int n;
    while(scanf("%d", &n) && n!=0){
        int i;
        for(i=0;i<110;i++)
            memset(tt[i], 0, 110*sizeof(double));
        for(i=0;i<n;i++){
            scanf("%d", &xx[i]);
//            cout<<xx[i]<<" ";
        }
//        cin>>b>>r>>v>>e>>f;
        scanf("%lf", &b);
        scanf("%d", &r);
        scanf("%lf", &v);
        scanf("%lf", &e);
        scanf("%lf", &f);
 //       cout<<b<<" "<<r<<" "<<v<<" "<<e<<" "<<f<<endl;
        //cout.precision(10);
        //cout<<run(-1, n-1)<<endl;
        printf("%-.4f\n", run(-1, n-1));
    }
}

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