UVa 10267 Problem: Graphical Editor (PC 110105)

来源:互联网 发布:网络维护难点分析 编辑:程序博客网 时间:2024/06/04 17:51
#include <iostream>#include <string>#include <string.h>#include <map>#include <stdio.h>#include <algorithm>#include <queue>#include <vector>#include <math.h>#include <set>#define Max(a,b) ((a)>(b)?(a):(b))#define Min(a,b) ((a)<(b)?(a):(b))#define SWAP(a , b){ int temp = a; a = b; b = temp;}#define Max_M 258#define Max_N 258using namespace std;int M;int N;char Graph[Max_N][Max_M];//保存图像int dir[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};//四个方向搜索//定义图像void IFun(){    scanf("%d%d",&M,&N);    for(int i = 1;i <= M;i++)        for(int j = 1;j <= N;j++)            Graph[j][i] = 'O';//是大写字母O , 而不是数字0!这个导致很多次WA}//清除图像void CFun(){    for(int i = 1;i <= N;i++)        for(int j = 1;j <= M;j++)            Graph[i][j] = 'O';//同样大写字母O}//设置某点的颜色void LFun(){    int X , Y;    char C;    cin>>X>>Y>>C;    Graph[Y][X] = C;}//画线和画区域可以合并void DrawRegion(char ins){    int X1, Y1, X2, Y2;    char C;    switch(ins)//发现switch比if快    {        case 'V':{ cin>>X1>>Y1>>Y2>>C; X2 = X1;break;}        case 'H':{ cin>>X1>>X2>>Y1>>C; Y2 = Y1;break;}        case 'K':{ cin>>X1>>Y1>>X2>>Y2>>C;break;}    }    if(X2 < X1) SWAP(X1 , X2);    if(Y2 < Y1) SWAP(Y1 , Y2);    for(int i = Y1;i <= Y2;i++)        for(int j = X1;j <= X2;j++)        Graph[i][j] = C;}//判断是否出界bool IsLegal(int x,int y){    return 1 <= x&&x <= N&&1 <= y&&y <=  M;}//深搜,找有共同边且颜色相同的点void DFS(int X,int Y,char C){    char color = Graph[Y][X];    if(color  == C) return;//新旧颜色相同时不做处理,否则递归无法结束    Graph[Y][X] = C;    for(int i =0;i <4;i++)    {        int x = Y + dir[i][0];        int y = X + dir[i][1];        if(IsLegal(x , y)&&Graph[x][y] == color)        {            DFS(y,x,C);        }    }}//区域填充颜色void FFun(){    int X, Y;    char C;    cin>>X>>Y>>C;    DFS(X, Y, C);}//输出void SFun(){    string s;    cin>>s;    cout<<s<<endl;    for(int i = 1;i <= N;i++)    {        for(int j = 1;j <= M;j++)            printf("%c",Graph[i][j]);        printf("\n");    }}int main(){    char Ins;    while(scanf("%c",&Ins),Ins != 'X')    {        switch(Ins)        {            case 'I':{IFun();break;}            case 'C':{CFun();break;}            case 'L':{LFun();break;}            case 'V':            case 'H':            case 'K':{DrawRegion(Ins);break;}            case 'F':{FFun();break;}            case 'S':{SFun();break;}        }    }    return 0;}
0 0