10267 - Graphical Editor

All about problems in Volume 102. 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
Caesum
Experienced poster
Posts: 225
Joined: Fri May 03, 2002 12:14 am
Location: UK
Contact:

10267 - Graphical Editor

Post 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 ?
Ivan Golubev
Experienced poster
Posts: 167
Joined: Fri Oct 19, 2001 2:00 am
Location: Saint Petersburg, Russia

Post 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...
arc16
Learning poster
Posts: 62
Joined: Sun Aug 04, 2002 1:05 am
Location: Indonesia

Re: 10267

Post 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
Caesum
Experienced poster
Posts: 225
Joined: Fri May 03, 2002 12:14 am
Location: UK
Contact:

Post 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.
arc16
Learning poster
Posts: 62
Joined: Sun Aug 04, 2002 1:05 am
Location: Indonesia

Post 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_.
Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

Can someone post some inputs/outputs? I've spent waaay too many WA's.. :cry:
jpfarias
Learning poster
Posts: 98
Joined: Thu Nov 01, 2001 2:00 am
Location: Brazil
Contact:

WA!!!

Post 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!
witto
New poster
Posts: 5
Joined: Fri Jan 18, 2002 2:00 am
Location: Sao Paulo - Brazil
Contact:

Post 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?
[]'s
Witto
jpfarias
Learning poster
Posts: 98
Joined: Thu Nov 01, 2001 2:00 am
Location: Brazil
Contact:

Solved

Post 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!
Dmytro Chernysh
Experienced poster
Posts: 146
Joined: Sat Apr 26, 2003 2:51 am

Post 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?
jpfarias
Learning poster
Posts: 98
Joined: Thu Nov 01, 2001 2:00 am
Location: Brazil
Contact:

Post 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!
Alexander Denisjuk
New poster
Posts: 35
Joined: Sat Jan 05, 2002 2:00 am
Contact:

Post 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.
Scryer
New poster
Posts: 4
Joined: Fri Jul 11, 2003 12:17 am

Post 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?
jpfarias
Learning poster
Posts: 98
Joined: Thu Nov 01, 2001 2:00 am
Location: Brazil
Contact:

Post by jpfarias »

I do it this way and got AC.

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

JP!
oriol78
New poster
Posts: 32
Joined: Mon Mar 31, 2003 7:39 pm

10267

Post 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 :-)
Post Reply

Return to “Volume 102 (10200-10299)”