您的位置:首页 > 其它

CCF 201512-3画图

2016-12-13 16:53 381 查看
//@start time:
//@finish time:
//@此处注意:行和列是反的
//@
/* 测试数据
16 13 9
0 3 1 12 1
0 12 1 12 3
0 12 3 6 3
0 6 3 6 9
0 6 9 12 9
0 12 9 12 11
0 12 11 3 11
0 3 11 3 1
1 4 2 C

16 13 8
0 3 1 12 1
0 12 1 12 3
0 12 3 6 3
0 6 3 6 9
0 6 9 12 9
0 12 9 12 11
0 12 11 3 11
0 3 11 3 1

*/
#include<iostream>
#include<cstring>
#include<vector>
#include<cmath>
int m,n,q;
char plot[102][102];
int flag[102][102];
void show();
void change(int x,int y,char c){
if((plot[x][y]==c)) return;

if((plot[x][y]=='.')||(flag[x][y]==1)){
plot[x][y]=c;
flag[x][y]=1;
if(x+1<=n)
change(x+1,y,c);
if(y+1<=m)
change(x,y+1,c);
if(x-1>=0)
change(x-1,y,c);
if(y-1>=0)
change(x,y-1,c);
}

}
using namespace std;
int main(){

memset(plot,'.',sizeof(plot));
memset(flag,0,sizeof(flag));
cin>>m>>n>>q;

for(int i=0;i<q;i++){
int action;
cin>>action;

if(!action){////action=0 画线操作
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
int start,over;
if(x1==x2){//画竖线 - -
start=y1<y2?y1:y2;
over=y2>y1?y2:y1;
for(int a=start;a<=over;a++){
flag[a][x1]=0;
if( plot[a][x1]=='-'|| plot[a][x1]=='+') plot[a][x1]='+';
else plot[a][x1]='|';
}
}

else {//y1=y2//画横线 | |
start=x1>x2?x2:x1;
over=x2>x1?x2:x1;

for(int a=start;a<=over;a++){
flag[y1][a]=0;
if( plot[y1][a]=='|'|| plot[y1][a]=='+') plot[y1][a]='+';
else plot[y1][a]='-';
}
}
}

else{//action=1 填充操作
int x,y;
char put;
cin>>y>>x;
cin>>put;
change(x,y,put);

}
}
show();
return 0;
}

void show(){

for(int i=n-1;i>-1;i--){
for(int j=0;j<m;j++){
cout<<plot[i][j];
}
cout<<endl;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: