ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1019. Line Painting

Why does this program gets Crash Access Violation? (+), thnks in advance :)
Posted by Miguel Angel 25 May 2002 05:57
#include<iostream.h>

struct line {
    long a, b;
    char c;
};

line *l;
int  ls;

void main()
{
int  n, i, j, pos;
line ll, h;
    cin>>n;
    l = new line[2*n+1];
   ls = 0;
    for (i=0; i<n; i++)
    {
        cin>>ll.a>>ll.b>>ll.c;
      if (ll.b - ll.a==0) continue;
                //compare with last lines not overlapped
        for (j=0; j<ls; j++)
        {
            if (ll.a<l[j].a && ll.b>l[j].b)
            {
                --ls;
                h=l[ls];l[ls]=l[j];l[j]=h;
                --j;
            }  else
            if (ll.a>l[j].a && ll.b<l[j].b)
            {
                l[ls]   = l[j];
                l[j].b  = ll.a;
                l[ls].a = ll.b;
                ls++;
            }  else
            if (l[j].a<ll.a && ll.a<l[j].b)
                l[j].b = ll.a;
                else
            if (l[j].a<ll.b && ll.b<l[j].b)
                l[j].a = ll.b;
        }// for (j)
        l[ls] = ll; ls++;
    }//for (i)
//sort them
    for (i=0; i<ls-1; i++)
    {
        pos = i;
        for (j=i+1; j<ls; j++)
            if (l[j].a<l[pos].a) pos=j;
        if (pos!=i)
        {
            h = l[i];
            l[i]=l[pos];
            l[pos]=h;
        }
    }
    line max, prev;
    max.a = 0;
    max.b = 1;
    prev.a = 0;
    prev.b = l[0].a;
    j = 0;
//go through the lines and get the maximum
    while ( j < ls )
    {
        while ( j < ls )
        {
            if (l[j].c=='w')
                prev.b = l[j].b;
            else
            {
                prev.b = l[j].a;
                break;
            }
            j++;
        }
        if (prev.b-prev.a>max.b-max.a)
            max = prev;
        if ( j < ls )
        {
            prev.a = l[j].b;
            prev.b = l[j].b;
        }
        j++;
    }
    if (1000000000-l[ls-1].b>max.b-max.a)
    {
        max.b = 1000000000;
        max.a = l[ls-1].b;
    }
    delete[] l;
   cout<<max.a<<" "<<max.b<<endl;
}
Ask SongChao
Posted by ECUST Multistar 25 May 2002 17:41
I can't understand you program.
But I give you a suggestion.
My friend SongChao Has Slove this problem with your method .
You could ask him about it.
And I think he'll give you a satisfy answer.
Here or by email? :) (-)
Posted by Miguel Angel 26 May 2002 05:13
> I can't understand you program.
> But I give you a suggestion.
> My friend SongChao Has Slove this problem with your method .
> You could ask him about it.
> And I think he'll give you a satisfy answer.
Re: Here or by email? :) (-)
Posted by LiangHonghao 26 May 2002 17:38
By E-mail.