528 - The Problem of Train Setout

All about problems in Volume 5. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
killerwife
New poster
Posts: 11
Joined: Tue Jan 28, 2014 2:16 am

528 - The Problem of Train Setout

Post by killerwife »

Code: Select all

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int arrivee,arriveo;
    int leavee,leaveo;
    int time;
    int expres[100000][2];
    int ordinary[100000][2];
    int i,j,k,l;
    int write;
    int starte,startl,starta;
    scanf("%d%d%d%d%d",&arrivee,&arriveo,&leavee,&leaveo,&time);
    i=j=k=l=starte=startl=write=0;
    while(i<=time)
    {
        if(i%arrivee==0)
        {
            expres[k][0]=i;
            k++;
            if(k>100000)
            {
                return 0;
            }
            write=1;
        }
        if(i%arriveo==0&&i!=0)
        {
            ordinary[l][0]=i;
            l++;
            if(l>100000)
            {
                return 0;
            }
            write=1;
        }
        if(j==0)
        {
            if(k>0)
            {
                expres[starte][1]=i-expres[starte][0];
                starte++;
                j=leavee;
            }
            else
            {
                if(l>0)
                {
                    ordinary[startl][1]=i-ordinary[startl][0];
                    startl++;
                    j=leaveo;
                }
            }
        }
        if(write==1)
        {
            write=0;
            printf("%d %d %d\n",i,k-starte,l-startl);
        }
        if(j>0)
        {
            j--;
        }
        i++;
    }
    printf("0\n");
    i=starte;
    while(i<k)
    {
        expres[i][1]=time-expres[i][0];
        i++;
    }
    i=startl;
    while(i<l)
    {
        ordinary[i][1]=time-ordinary[i][0];
        i++;
    }
    i=0;
    starte=startl=starta=0;
    while(i<k)
    {
        starta=starta+expres[i][1];
        starte=starte+expres[i][1];
        i++;
    }
    i=0;
    while(i<l)
    {
        starta=starta+ordinary[i][1];
        startl=startl+ordinary[i][1];
        i++;
    }
    printf("%d %d %d\n0\n",starte/(k),startl/(l),starta/(l+k));
    i=0;
    while(i<k)
    {
        printf("E%d %d\n",i+1,expres[i][1]);
        i++;
    }
    i=0;
    while(i<l)
    {
        printf("O%d %d\n",i+1,ordinary[i][1]);
        i++;
    }
    return 0;
}
I always get runtime error. Dunno why.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 528

Post by brianfry713 »

http://uva.onlinejudge.org/index.php?op ... category=7
528 has a red check so the judge doesn't have I/O for it and you can't get AC.
Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “Volume 5 (500-599)”