Page 1 of 13

10267 - Graphical Editor

Posted: Tue Aug 13, 2002 10:43 pm
by Caesum
Does anyone know what:

In case of other errors the program behaviour is unpredictable.

means ? What if the parameters of a command are beyond the bounds of the bitmap, do you draw half a line or ignore the whole command ?

Any other strange trickery in this question ?

Posted: Tue Aug 13, 2002 11:18 pm
by Ivan Golubev
I can't say nothing useful about this problem, sorry. But just an one thing I've figure out -- 'Alexander Denisjuk' is the worst problem setter I've ever faced...

Re: 10267

Posted: Sun Sep 01, 2002 5:44 pm
by arc16
Caesum wrote:Does anyone know what:

In case of other errors the program behaviour is unpredictable.

means ? What if the parameters of a command are beyond the bounds of the bitmap, do you draw half a line or ignore the whole command ?

Any other strange trickery in this question ?
i don't know. i think we should draw half of the line ( ex: if x2>m -> x2=m). Or maybe draw the rest of the line in the next column/row since it said about unpredictable behavior..

i'm still having trouble with this problem, got RE. I think it come from stack overflow caused by my flood fill function. Is there any good technique to do flood fill without worry about stack overflow? I'm currently using recursif.

thanks

Posted: Fri Sep 06, 2002 11:34 am
by Caesum
personally i use an iterative flood fill, looping until no further changes have been made, its to easy to fill the stack with recursion, the judge seems to fall over after about 20 depths mostly.

Posted: Fri Sep 06, 2002 7:34 pm
by arc16
Caesum wrote:personally i use an iterative flood fill, looping until no further changes have been made, its to easy to fill the stack with recursion, the judge seems to fall over after about 20 depths mostly.
thank you, fix that, and AC! ^_^
we don't need to worry about unpredictable behaviour thing, just be sure to handle filling command with the _same color_.

Posted: Mon Feb 24, 2003 1:41 pm
by Larry
Can someone post some inputs/outputs? I've spent waaay too many WA's.. :cry:

WA!!!

Posted: Wed Jun 04, 2003 6:03 pm
by jpfarias
I'm about to became crazy on this problem!

I'm filling iteractively, I take care of filling with the same color (just do nothing), and I've done lot's of tests, but I just got WA, WA, WA, WA, WA, WA......


Can anyone help?

I'll explain a bit what my program do:

Code: Select all

1. read command (command is a char[10000])
2. if (command[1] != '\0') skip line and go back to 1 (test if command is 1 char only, I've made a test ignoring this too and looking only the first char, but WA)
3. if command is invalid skip line and go back to 1
4. process command
Some questions:
1. Can it be any commands after a X command?
2. Can a S happen with no NAME? (just S on a line)
3. If the color is not a upper case letter, should I use it?
4. I skip the line with fgets(cmd, 10000, stdin); Can a line be > then 10000 chars?
5. Can the filename on S command be > 20 chars? (DOS 8.3 uses one 12 + '\0' chars)
6. Is diagonal neighbours of a pixel?
7. Can u think in any other problem in this problem?

Thanks!

JP!

Posted: Sun Jun 08, 2003 11:30 pm
by witto
I seems like you figured out what your problem was.

I am facing the same problems here and don't know why I'm getting WA. Can you give any hint to help me solve the problem?

Solved

Posted: Wed Jun 11, 2003 3:06 am
by jpfarias
There's nothing special in the input....
To solve this problem, just read the command and assume it is ok, check the first char to see what to do and do what you need to do...

Just take care the fill with same color. When filling, check if oldcolor == newcolor, if it's true, do nothing!

I think I've helped...

Any questions? Just ask and I'll see if I can answer!

JP!

Posted: Wed Jun 11, 2003 5:57 am
by Dmytro Chernysh
Hi jpfarias!

So you solved this problem? Very good, because I am getting only WA. But I think I did everything correct according to the problem.

Can you help me?

Posted: Wed Jun 11, 2003 2:34 pm
by jpfarias
do the following:

Code: Select all


1. read command (as a string)
2. switch on the first letter of command
3. process the command (with no error checking)
4. if command is not on the list of commands, ignore just the command, not the whole line...
5. done!

Take care when printing also, print just m chars per line + the \n.

JP!

Posted: Thu Jun 12, 2003 9:30 am
by Alexander Denisjuk
Dear colleagues,
thank you very much for you interest in my problem. Special
thanks to "Ivan Golubev" for his interest in my person.
The problem with graphical editor is very old and widely spread.
I believe you can find this problem or some of it parts in every
programming manual. Since I signed the variant for Online Judge,
let me answer the questions (I insist that all the answer are in the problem description):
1. Can it be any commands after a X command?
I think it does not matter since X terminates the session.
2. Can a S happen with no NAME? (just S on a line)
3. If the color is not a upper case letter, should I use it?
By default all the input data for the problems are correct. The "errors"
section of the problem description claims that the only
error in input data you should care about is wrong first letter in a line.
"In case of other errors the program behaviour is
unpredictable" simply means that there will not be any other
error.
4. I skip the line with fgets(cmd,10000, stdin); Can a line be > then 10000 chars?
I used readln :D I do not remember the tests I submitted, but I do
not think there are so long lines. It is not the matter of the
problem.
5. Can the filename on S command be > 20 chars? (DOS 8.3 uses one 12 + '\0' chars)
I do not think that 12 can be >20.
6. Is diagonal neighbours of a pixel?
No, since there should be a "common side".
7. Can u think in any other problem in this problem?
Well, there is nothing special in this problem. Just verify, what
is the number of rows, what is the number of columns, check how
do you fill the segment between X1 and X2. I was told that in C
the arrays (I guess you use array) are numbered from 0, in the
problem --- from 1. As to region filling algorithm, I used so
called "stack of postponed jobs". But I have heard that the recursive
one is also OK.

Posted: Fri Jul 11, 2003 12:26 am
by Scryer
[quote="jpfarias"]do the following:

Code: Select all

1. read command (as a string)
2. switch on the first letter of command
3. process the command (with no error checking)
4. if command is not on the list of commands, ignore just the command, not the whole line...
5. done!
#4 seems to contradict the problem statement, which says explicitly that we are to ignore the whole line. Are you sure about this one?

Posted: Fri Jul 11, 2003 1:03 pm
by jpfarias
I do it this way and got AC.

I really think there are no illegal commands on the input, though. :-)

JP!

10267

Posted: Sun Jul 20, 2003 10:47 pm
by oriol78
well, my code produces WA but i ca't see my mistake, can anyone help me plz?
[cpp]
#nclude <iostream>
#include <vector>
#include <string>
using namespace std;

vector<vector<char> > matrix(251,vector<char>(251));
int tamX,tamY;

void fill(int x, int y, char color, char colorAnt)
{
matrix[x][y] = color;
if(x-1 >= 0 && matrix[x-1][y] == colorAnt)
fill(x-1,y,color,colorAnt);
if(y-1 >= 0 && matrix[x][y-1] == colorAnt)
fill(x,y-1,color,colorAnt);
if(x+1 < tamX && matrix[x+1][y] == colorAnt)
fill(x+1,y,color,colorAnt);
if(y+1 < tamY && matrix[x][y+1] == colorAnt)
fill(x,y+1,color,colorAnt);
}

void proces(char c)
{
switch(c)
{
case 'I':
{
cin >> tamY >> tamX;
proces('C');
break;
}
case 'C':
{
for(int i = 0; i < 251; i++)
{
for(int j = 0; j < 251; j++)
matrix[j] = 'O';
}
break;
}
case 'L':
{
int x,y;
char color;
cin >> x >> y >> color;
matrix[y-1][x-1] = color;
break;
}
case 'V':
{
int x,y1,y2;
char color;
cin >> x >> y1 >> y2 >> color;
for(int j = y1; j <= y2; j++)
matrix[j-1][x-1] = color;
break;
}
case 'H':
{
int x1,x2,y;
char color;
cin >> x1 >> x2 >> y >> color;
for(int i = x1; i <= x2; i++)
matrix[y-1][i-1] = color;
break;
}
case 'K':
{
int x1,x2,y1,y2;
char color;
cin >> x1 >> y1 >> x2 >> y2 >> color;
for(int i = x1; i <= x2; i++)
{
for(int j = y1; j <= y2; j++)
matrix[j-1][i-1] = color;
}
break;
}
case 'F':
{
int x,y;
char color;
cin >> x >> y >> color;
if(color != matrix[y-1][x-1])
fill(y-1,x-1,color, matrix[y-1][x-1]);
break;
}
case 'S':
{
string name;
cin >> name;
cout << name << endl;
for(int i = 0; i < tamX; i++)
{
for(int j = 0; j < tamY; j++)
cout << matrix[j];
cout << endl;
}
break;
}
default:
{
string aux;
getline(cin,aux);
}
}
}

int main()
{
char instr;
cin >> instr;
while(instr != 'X')
{
proces(instr);
cin >> instr;
}
return 0;
}
[/cpp]

thx :-)