105 - The Skyline Problem

All about problems in Volume 1. 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
Zheng
New poster
Posts: 6
Joined: Mon May 06, 2002 12:27 pm
Location: Xi'an, China

105

Post by Zheng »

I try to do the problem 105, but received this:

Warning: Your program would get a Presentation Error in a true contest.
The 24-hours judge interpretes it as an "Accepted" problem.

what does it mean?

[cpp]
#include <fstream>
#include <iostream>

using namespace std;

#ifndef ONLINE_JUDGE
ifstream FIN("skyline.in");
#else
istream& FIN = cin;
#endif

ostream& FOUT = cout;

void main()
{
int H[10002] = {0};
while(FIN && !FIN.eof())
{
int l,h,r;
FIN>>l>>h>>r;
for(int i=l;i<r;i++)
{
if(H<h)
H = h;
}
}

for(int i=1;i<10002;i++)
{
if(H!=H[i-1])
FOUT<<i<<' '<<H<<' ';
}
}
[/cpp]

10153EN
Experienced poster
Posts: 148
Joined: Sun Jan 06, 2002 2:00 am
Location: Hong Kong
Contact:

Hi~~

Post by 10153EN »

You received Accepted (P.E.). Right?

That means that your output matches with the sample output for the content, but differs with some minor things. e.g. space, the return at the end of the line, a blank line, etc.

Zheng
New poster
Posts: 6
Joined: Mon May 06, 2002 12:27 pm
Location: Xi'an, China

Post by Zheng »

but what the minor thing is?

10153EN
Experienced poster
Posts: 148
Joined: Sun Jan 06, 2002 2:00 am
Location: Hong Kong
Contact:

Post by 10153EN »

I think for this problem (105), the P.E. is resulted from missing the '\n' at the end of the sequence of output numbers.

Try to add a '\n' at the end of the numbers and it will be got accepted.

Zheng
New poster
Posts: 6
Joined: Mon May 06, 2002 12:27 pm
Location: Xi'an, China

Post by Zheng »

I added a "endl" at the end, but the message is still P.E. :cry:

BIG5:

10153EN
Experienced poster
Posts: 148
Joined: Sun Jan 06, 2002 2:00 am
Location: Hong Kong
Contact:

Post by 10153EN »

Oh, I found another minor printing error by having taken a look at your code.

Your output is printed by
[cpp]
for(int i=1;i<10002;i++)
{
if(H!=H[i-1])
FOUT<<i<<' '<<H<<' ';
}
[/cpp]
The above code will print the numbers with a space after each number. Right?
e.g. If the number to be outputted is 1 2 3 4 5 6, you will print

1_2_3_4_5_6_\n

where _ stands for a space character
and \n stands for a new line character

However, the standand output should be

1_2_3_4_5_6\n

So you got what I mean? (Haha... my poor English~~)

Pokemonster
New poster
Posts: 10
Joined: Mon Jul 01, 2002 11:15 pm
Location: Germany

105 Help with SIGSEGV Error

Post by Pokemonster »

Can anyone help ?

I keep getting SIGSEGV errors when submitting and I can't figure out why ...

[cpp]
#include <stdio.h>
#include <string.h>
#include <malloc.h>

main()
{
/* redirect standard input + output if necessary */
#ifndef ONLINE_JUDGE
freopen( "data.in", "r", stdin );
freopen( "data.out", "w", stdout );
#endif

/* load input */
int iLeft, iTop, iRight;
int i;

int *iSkyline = (int*)malloc(5000*sizeof(int));
for( i=0; i<=5000; i++)
iSkyline=0;

while( scanf("%d %d %d", &iLeft, &iTop, &iRight) != EOF )
{
/* get height map */
for( int j=iLeft; j<iRight; j++ )
{
if( iSkyline[j] < iTop )
iSkyline[j] = iTop;
}
}

/* start output */
int iCurrentHeight = 0;
for( i=0; i<= 5000; i++ )
{
if( iCurrentHeight != iSkyline )
{
printf("%i %i ", i, iSkyline );
iCurrentHeight = iSkyline;
}
}
}
[/cpp]

Ivan Golubev
Experienced poster
Posts: 167
Joined: Fri Oct 19, 2001 2:00 am
Location: Saint Petersburg, Russia

Post by Ivan Golubev »

AFAIR, there can be negative numbers in input.

Pokemonster
New poster
Posts: 10
Joined: Mon Jul 01, 2002 11:15 pm
Location: Germany

Post by Pokemonster »

You mean in the judge's input ?
My guess was that the array I allocate is too big ...

Ivan Golubev
Experienced poster
Posts: 167
Joined: Fri Oct 19, 2001 2:00 am
Location: Saint Petersburg, Russia

Post by Ivan Golubev »

Yes, in judge's input (is there another input? ;-) ).

And, actually, your array is too small. As I can understand it must be 10000 at least. And including negative numbers it must be a bit more than 20000.

Pokemonster
New poster
Posts: 10
Joined: Mon Jul 01, 2002 11:15 pm
Location: Germany

Problem 105 - Presentation Error

Post by Pokemonster »

Hi!
I'm wondering if anyone else got a presentation error after submitting. The program is accepted, but there's something wrong with the output and I can't figure what !? ( No extra spaces / CRs etc ... )

Sample Input:
  • 1 11 5
    2 6 7
    3 13 9
    12 7 16
    14 3 25
    19 18 22
    23 13 29
    24 4 28
Sample Output:
  • 1 11 3 13 9 0 12 7 16 3 19 18 22 3 23 13 29 0
Any clues ?

10153EN
Experienced poster
Posts: 148
Joined: Sun Jan 06, 2002 2:00 am
Location: Hong Kong
Contact:

Post by 10153EN »

Do you have a space character after the last 0?

Pokemonster
New poster
Posts: 10
Joined: Mon Jul 01, 2002 11:15 pm
Location: Germany

Post by Pokemonster »

No, I removed that after the first presentation error message :-)

10153EN
Experienced poster
Posts: 148
Joined: Sun Jan 06, 2002 2:00 am
Location: Hong Kong
Contact:

Post by 10153EN »

Then any newline character after the last 0?

Pokemonster
New poster
Posts: 10
Joined: Mon Jul 01, 2002 11:15 pm
Location: Germany

Post by Pokemonster »

Nope, nothing.
My modified output version looks like that
[cpp]
int iCurrentHeight = 0;
int bFirst = true;
for( i=0; i< 10000; i++ )
{
if( iCurrentHeight != iSkyline )
{
if(bFirst)
{
printf("%i %i", i, iSkyline );
bFirst = false;
}
else
{
printf(" %i %i", i, iSkyline );
}
iCurrentHeight = iSkyline;
}
}
[/cpp]

Post Reply

Return to “Volume 1 (100-199)”