Page 1 of 11

105

Posted: Mon May 06, 2002 12:44 pm
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]

Hi~~

Posted: Mon May 06, 2002 1:53 pm
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.

Posted: Wed May 08, 2002 9:19 am
by Zheng
but what the minor thing is?

Posted: Wed May 08, 2002 9:35 am
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.

Posted: Wed May 08, 2002 10:47 am
by Zheng
I added a "endl" at the end, but the message is still P.E. :cry:

BIG5:

Posted: Wed May 08, 2002 12:15 pm
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~~)

105 Help with SIGSEGV Error

Posted: Mon Jul 01, 2002 11:18 pm
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]

Posted: Tue Jul 02, 2002 12:35 am
by Ivan Golubev
AFAIR, there can be negative numbers in input.

Posted: Tue Jul 02, 2002 12:53 am
by Pokemonster
You mean in the judge's input ?
My guess was that the array I allocate is too big ...

Posted: Tue Jul 02, 2002 1:01 am
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.

Problem 105 - Presentation Error

Posted: Tue Jul 02, 2002 5:50 pm
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 ?

Posted: Tue Jul 02, 2002 5:52 pm
by 10153EN
Do you have a space character after the last 0?

Posted: Tue Jul 02, 2002 6:12 pm
by Pokemonster
No, I removed that after the first presentation error message :-)

Posted: Tue Jul 02, 2002 6:19 pm
by 10153EN
Then any newline character after the last 0?

Posted: Tue Jul 02, 2002 6:24 pm
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]