描述

坐标离散化的思想就是把有用的坐标提取出来,再建一个坐标系,把这些坐标按照顺序放在这个坐标系中。本题只需存储直线的x,y坐标和直线前后的。所以大小6n*6n就够了。
关键函数代码是compress()
很直观的表现出来了,你们运行输入样例就知道我的代码是干嘛的了。

输入

20 20
7
2 0 2 3
1 8 20 8
1 19 2 19
9 3 16 3
8 1 8 20
15 1 15 15
8 10 20 10

c++代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <complex>
#include <vector>
#include <cstdio>
using namespace std;
#define ll long long
#define N 100
char mp[N][N];
int l,w,n;
struct line
{
int sx,sy;
int ex,ey;
}lol[N];
int x[N*2],y[N*2],cnt=0;
void clear(){
for(int i=1 ; i<=l ;i++)
for(int j=1 ; j<=w ;j++ )
mp[i][j]='.';
}
void draw_show(){
for(int i=1 ;i<= n ;i++){
int sx=lol[i].sx,sy=lol[i].sy,ex=lol[i].ex,ey=lol[i].ey;
if(sx==ex){
for(int j=min(sy,ey) ; j<=max(sy,ey) ; j++)
mp[sx][j]='#';
}
else{
for(int j=min(sx,ex) ; j<=max(sx,ex) ; j++)
mp[j][sy]='#';
}
}
for(int i=1 ; i<=l ;i++)
for(int j=1 ; j<=w ;j++ )
printf("%c%c",mp[i][j],j==w?'\n':' ');
}
void change(){
int cc=0;
for(int i=1 ;i <=n ;i++){
lol[i].sx=x[++cc],lol[i].sy=y[cc];
lol[i].ex=x[++cc],lol[i].ey=y[cc];
}
}
int compress(int *x,int l){
int tk[N+N],fk=0;
for(int i=1 ; i<=cnt ;i++)
for(int j=-1 ;j<=1 ;j++){
if(x[i]+j>=1 && x[i]+j<= l){
tk[fk++]=x[i]+j;
}
}
sort(tk,tk+fk);
int size=unique(tk,tk+fk)-tk;
for(int i=1 ;i<=cnt ;i++)
x[i] = lower_bound(tk,tk+size,x[i])-tk +1 ;
return size;
}
int main(){
//只限横竖直线
while(~scanf("%d%d",&l,&w) ){
memset(mp,0,sizeof(mp));
cout<<"line's number and their start pots ans ends pots"<<endl;
cin>>n;cnt=0;
for(int i=1 ;i<= n ;i++){
cin>>lol[i].sx>>lol[i].sy>>lol[i].ex>>lol[i].ey;
x[++cnt]=lol[i].sx,y[cnt]=lol[i].sy;
x[++cnt]=lol[i].ex,y[cnt]=lol[i].ey;
}
clear();
draw_show();
puts("________________________________");
l=compress(x,l);
cout<<" l = "<<l<<endl;
w=compress(y,w);
cout<<" w = "<<w<<endl;
change();
clear();
draw_show();
}
return 0;
}