10267 - Graphical Editor
Moderator: Board moderators
10267 - Graphical Editor
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 ?
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 ?
-
- Experienced poster
- Posts: 167
- Joined: Fri Oct 19, 2001 2:00 am
- Location: Saint Petersburg, Russia
Re: 10267
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..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'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
thank you, fix that, and AC! ^_^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.
we don't need to worry about unpredictable behaviour thing, just be sure to handle filling command with the _same color_.
WA!!!
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:
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!
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
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!
Solved
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!
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!
-
- Experienced poster
- Posts: 146
- Joined: Sat Apr 26, 2003 2:51 am
do the following:
Take care when printing also, print just m chars per line + the \n.
JP!
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!
JP!
-
- New poster
- Posts: 35
- Joined: Sat Jan 05, 2002 2:00 am
- Contact:
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):
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.
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.
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.
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):
I think it does not matter since X terminates the session.1. Can it be any commands after a X command?
By default all the input data for the problems are correct. The "errors"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?
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.
I used readln4. I skip the line with fgets(cmd,10000, stdin); Can a line be > then 10000 chars?
![:D](./images/smilies/icon_biggrin.gif)
not think there are so long lines. It is not the matter of the
problem.
I do not think that 12 can be >20.5. Can the filename on S command be > 20 chars? (DOS 8.3 uses one 12 + '\0' chars)
No, since there should be a "common side".6. Is diagonal neighbours of a pixel?
Well, there is nothing special in this problem. Just verify, what7. Can u think in any other problem in this problem?
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.
[quote="jpfarias"]do the following:
#4 seems to contradict the problem statement, which says explicitly that we are to ignore the whole line. Are you sure about this one?
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!
10267
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![:-)](./images/smilies/icon_smile.gif)
[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
![:-)](./images/smilies/icon_smile.gif)