UVa 10267 Graphical Editor
来源:互联网 发布:php重载 编辑:程序博客网 时间:2024/06/05 10:56
【题号】UVa 10267 - Graphical Editor
【题目描述】
Problem
The simple graphical editor deals with a rectangular table M×N (1<=M,N<=250). Each pixel of the table has its colour. The picture is formed from this square pixels.
The problem is to write a program, which simulates an interactive work of the graphical editor.
Input
Input consists of the editor commands, one per line. Each command is represented by one Latin capital placed in the very beginning of the line. If the command supposes parameters, all the parameters will be given in the same line separated by space. As the parameters there may be: the coordinates of the pixel - two integers, the first one is the column number and belongs to 1..M, the second one is the row number and belongs to 1..N, the origin is in the upper left corner of the table; the colour - the Latin capital; file name - in MSDOS 8.3 format.
The editor deals with the following commands:
Output
Every time the command S NAME meets, you should output the file name NAME and the current table, row by row. Each row is represented by a pixels' colours series, see the output sample.
Errors
If as a command there will be a character different from I, C, L, V, H, K, F, S, X, the editor should ignore the whole line and pass to the next command.
In case of other errors the program behaviour is unpredictable.
Sample Input
I 5 6L 2 3 AS one.bmpG 2 3 JF 3 3 JV 2 3 4 WH 3 4 2 ZS two.bmpX
Sample Output
one.bmpOOOOOOOOOOOAOOOOOOOOOOOOOOOOOOtwo.bmpJJJJJJJZZJJWJJJJWJJJJJJJJJJJJJ
Alexander Denisjuk, 2002
【类型】
简单题,但略坑
【分析】
题目不难,可是数据确实有点坑。
第一个注意:表格第7行那个填充区域R的那个描述:需要注意,填充区域R,若像素(x,y)属于R,那么所有与(x,y)有公共边并且颜色相同的像素都属于R;这样需要深搜一下,从g[y-1][x-1]点DFS遍历一下,走过的路全部涂上颜色。
第二个注意:X1不一定比X2小,Y1也不一定比Y2小。
【源代码】
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <string>using namespace std;const int Max = 250 + 5;int n,m; //行号和列号 char g[Max][Max];int vis[Max][Max]; //标记 char cmmd[20]; int dir[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};void draw1(int M, int N) //创建像素矩阵 {n = N;m = M;memset(g, 'O', sizeof(g));}void draw2() //清除图像,像素涂成白色 {memset(g, 'O', sizeof(g)); //注意白色是'O'不是'0' }void draw3(int x, int y, char c) //把g[y-1][x-1]涂成白色{g[y-1][x-1] = c;}void draw4(int x, int y1, int y2, char c){ //将g[(y1-1)~(y2-1) or (y2-1)~(y1-1)][x-1] if(y1 > y2)swap(y1, y2);for(int i = y1-1; i <= y2-1; i++){g[i][x-1] = c;}}void draw5(int x1, int x2, int y, char c)//将g[y-1][(x1-1)~(x2-1) or (x2-1)~(x1-1)] {if(x1 > x2)swap(x1,x2);for(int i = x1-1; i <= x2-1; i++){g[y-1][i] = c;}}//左上角为(y1-1,x1-1),右下角为(y2-1,x2-1)的矩形涂满颜色c void draw6(int x1, int y1, int x2, int y2, char c) {for(int i=y1-1; i<=y2-1; i++){for(int j=x1-1; j<=x2-1; j++){g[i][j] = c;} }}char k;//中心点g[y-1][x-1]的颜色 void draw7(int x, int y, char c) //考虑和g[y-1][x-1]一同属于区域R的像素点 {int tx,ty;for(int i=0; i<4; i++){tx = x + dir[i][0];ty = y + dir[i][1];if(tx >= 0 && tx < n && ty >= 0 && ty < m && !vis[tx][ty] && g[tx][ty] == k){g[tx][ty] = c;vis[tx][ty] = 1;draw7(tx, ty, c);}}}void draw8(char str[]) //输出文件名及像素矩阵 {printf("%s\n",str);for(int i=0; i<n; i++){for(int j=0; j<m; j++){printf("%c",g[i][j]);}printf("\n");}}int main(){int x,y,x1,y1,x2,y2,M,N;char c;while(scanf("%s",cmmd) && cmmd[0] != 'X'){if(cmmd[0] == 'I') {scanf("%d %d",&M,&N);draw1(M, N);}else if(cmmd[0] == 'C'){draw2();}else if(cmmd[0] == 'L'){scanf("%d %d %c",&x,&y,&c);draw3(x, y, c);}else if(cmmd[0] == 'V'){scanf("%d %d %d %c",&x,&y1,&y2,&c);draw4(x, y1, y2, c);}else if(cmmd[0] == 'H'){scanf("%d %d %d %c",&x1,&x2,&y,&c);draw5(x1, x2, y, c);}else if(cmmd[0] == 'K'){scanf("%d %d %d %d %c",&x1,&y1,&x2,&y2,&c);draw6(x1, y1, x2, y2, c); }else if(cmmd[0] == 'F'){scanf("%d %d %c",&x,&y,&c);memset(vis, 0 ,sizeof(vis));k = g[y-1][x-1];g[y-1][x-1] = c;vis[y-1][x-1] = 1;draw7(y-1, x-1, c);} else if(cmmd[0] == 'S'){scanf("%s",cmmd);draw8(cmmd);}else //不合法 {gets(cmmd); //将后面的输入完 }}return 0; }
- uva-10267 - Graphical Editor
- UVa 10267-Graphical Editor
- uva 10267 Graphical Editor
- UVA 10267 - Graphical Editor
- UVa 10267 Graphical Editor
- UVa 10267 Graphical Editor
- UVa 10267 Graphical Editor
- UVa OJ 10267Graphical Editor
- UVa Problem Solution: 10267 - Graphical Editor
- 简单模拟 UVa 10267 - Graphical Editor
- UVa 10267 Problem: Graphical Editor (PC 110105)
- 10267 - Graphical Editor
- 10267 - Graphical Editor
- UVa Problem 10267 Graphical Editor (图形化编辑器)
- UVa Problem 10267 Graphical Editor (图形化编辑器)
- PC/Uva 11015/10267 图形编辑器(Graphical Editor)
- Graphical Editor
- 110105 Graphical Editor
- SPOJ 3267. D-query (主席树or树状数组离线)
- ACM-BestCoder Round #21
- Android使用XlistView做出上下拉刷新功能
- [统计学习]Rocchio算法
- HDU 3333 树状数组离线
- UVa 10267 Graphical Editor
- SQL*PLUS命令的使用大全
- String与StringBuffer和StringBuilder区别之一
- Audio笔记之AudioSystem::getOutput
- 《现代操作系统—中文第三版》读书笔记之——调度算法
- BestCoder Round #21 1002
- 动态规划算法
- 终于解决了贴吧手机版的一个重大BUG
- 电子书格式探秘