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 476629805 at 2013-06-11 13:07:08 on Problem 1661
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int Maxn=1000;
const int INF=1e6;

typedef struct platform
{
    int lx,rx,h;
}Platform;
Platform aplatform[Maxn+5];
int LeftMinTime[Maxn+5];
int RightMinTime[Maxn+5];
int n,x,y,maxh,t;

int cmp(const void *e1, const void *e2)
{
    Platform *p1,*p2;
    p1=(Platform *)e1;
    p2=(Platform *)e2;
    return p2->h - p1->h;
}

int MinTime(int L, bool bleft)
{
    int y = aplatform[L].h;
    int x;
    if(bleft)
        x = aplatform[L].lx;
    else
        x = aplatform[L].rx;
    int i;
    for(i=L+1;i<=n;i++)
        if(aplatform[i].lx <= x && aplatform[i].rx >= x)
            break;
    if(i<=n)
    {
        if((aplatform[L].h - aplatform[i].h) > maxh)
            return INF;
    }
    else
    {
        if(y > maxh)
            return INF;
        else
            return y;
    }
    int nLeftMinTime;
    int nRightMinTime;
    if(LeftMinTime[i] == -1)
    {
        LeftMinTime[i] = MinTime(i,true);
    }
    if(RightMinTime[i] == -1)
    {
        RightMinTime[i] = MinTime(i,false);
    }
    nLeftMinTime = y-aplatform[i].h+x-aplatform[i].lx+LeftMinTime[i];
    nRightMinTime = y-aplatform[i].h+aplatform[i].rx-x+RightMinTime[i];
    if(nLeftMinTime > nRightMinTime)
        return nRightMinTime;
    else
        return nLeftMinTime;
}

int main()
{
    cin >> t;
    while(t--)
    {
        memset(LeftMinTime,-1,sizeof(LeftMinTime));
        memset(RightMinTime,-1,sizeof(RightMinTime));
        cin >> n >> x >> y >> maxh;
        aplatform[0].lx = aplatform[0].rx = x;
        aplatform[0].h = y;
        for(int i=1;i<=n;i++)
            cin >> aplatform[i].lx >> aplatform[i].rx >> aplatform[i].h;
        qsort(aplatform,n+1,sizeof(Platform),cmp);
        cout << MinTime(0,true) << endl;
    }
}

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