-
Notifications
You must be signed in to change notification settings - Fork 0
/
task45-rect1.c
119 lines (106 loc) · 1.95 KB
/
task45-rect1.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
ID: zltsang1
LANG: C
TASK: rect1
*/
#include <stdio.h>
#include <assert.h>
typedef long long int64;
typedef long int32;
#define xn 10000
typedef struct rectangle rect;
struct rectangle{
int lx, ly, rx, ry, clr;
};
rect ary[xn];
int arc;
#define xc 2500
int ara[xc+1];
int sar(rect rt){
return (rt.ry-rt.ly)*(rt.rx-rt.lx);
}
int check(int a,int b){
int i;
int s=a*b;
rect rt;
for(i=0;i<arc;i++){
rt=ary[i];
s-=sar(rt);
}
if(s)return 1;
return 0;
}
main () {
FILE *fin = fopen ("rect1.in", "r");
FILE *fout = fopen ("rect1.out", "w");
//fout=stdout;
int aa,ab,an;
int i,j,cr;
rect rt,rti,*rp;
fscanf (fin, "%d %d %d", &aa,&ab,&an);
rt.lx=0;rt.ly=0;rt.rx=aa;rt.ry=ab;rt.clr=1;
ary[0]=rt;
arc=1;rp=ary+arc;
for(i=1;i<=an;i++){
fscanf (fin, "%d %d %d %d %d", &rt.lx,&rt.ly,&rt.rx,&rt.ry,&rt.clr);
//add rt to ary,split rects.
for(j=0;j<arc;j++){
rti=ary[j];
if(rt.lx>=rti.rx||rt.rx<=rti.lx||rt.ly>=rti.ry||rt.ry<=rti.ly)continue;
//rp=ary+arc;
cr=0;
if(rti.lx<rt.lx){
rp->lx=rti.lx;
rp->ly=rti.ly;
rp->rx=rt.lx;
rp->ry=rti.ry;
rp->clr=rti.clr;
rp++;cr++;
rti.lx=rt.lx;
}
if(rti.rx>rt.rx){
rp->lx=rt.rx;
rp->ly=rti.ly;
rp->rx=rti.rx;
rp->ry=rti.ry;
rp->clr=rti.clr;
rp++;cr++;
rti.rx=rt.rx;
}
if(rti.ly<rt.ly){
rp->lx=rti.lx;
rp->ly=rti.ly;
rp->rx=rti.rx;
rp->ry=rt.ly;
rp->clr=rti.clr;
rp++;cr++;
rti.ly=rt.ly;
}
if(rti.ry>rt.ry){
rp->lx=rti.lx;
rp->ly=rt.ry;
rp->rx=rti.rx;
rp->ry=rti.ry;
rp->clr=rti.clr;
rp++;cr++;
rti.ry=rt.ry;
}
assert(rp-ary<=xn);
{rp--;ary[j]=rp[0];}//dont waste ary[j]
if(rp-ary<arc){arc--;j--;}//this is the hard case
}
rp[0]=rt;rp++;
arc=rp-ary;
assert(check(aa,ab)==0);
}
arc=rp-ary;
for(i=0;i<arc;i++){
rt=ary[i];
ara[rt.clr]+=sar(rt);
}
for(i=1;i<xc+1;i++){
if(ara[i]>0)
fprintf (fout, "%d %d\n",i,ara[i]);
}
exit (0);
}