比这篇新的文章:
checker.final.cpp
比这篇旧的文章: humble.cpp
作者: xpycc, 点击265次, 评论(0), 收藏者(0)
打分:
所有评论,共0条:( 我也来说两句)
比这篇旧的文章: humble.cpp
rect1.pas
语言: Delphi, 标签: 无 2008/08/22发布 3个月前更新作者: xpycc, 点击265次, 评论(0), 收藏者(0)
Delphi语言: rect1.pas
001 {
002 ID:xpycc1
003 PROG:rect1
004 LANG:PASCAL
005 }
006
007 program rect1;
008 const
009 maxcolor=2500;
010 maxq=100000;
011 type
012 squr=record
013 x1,x2,y1,y2,color:integer;
014 end;
015 var
016 res:array[1..maxcolor]of longint;
017 q:array[0..maxq]of squr;
018 n,rx2,ry2,wx1,wx2,wy1,wy2,c,kx1,ky1,kx2,ky2:integer;
019 s,e,ep,i:longint;
020 f:boolean;
021 //
022 function min(x,y:integer):integer;
023 begin
024 if x>y then min:=y
025 else min:=x;
026 end;
027 //
028 function max(x,y:integer):integer;
029 begin
030 if x>y then max:=x
031 else max:=y;
032 end;
033 //
034 begin
035 s:=0; e:=1;
036 assign(input,'rect1.in'); reset(input);
037 readln(rx2,ry2,n);
038 with q[s] do
039 begin
040 x1:=0;
041 x2:=rx2;
042 y1:=0;
043 y2:=ry2;
044 color:=1;
045 end;
046 while n>0 do
047 begin
048 readln(kx1,ky1,kx2,ky2,c);
049 i:=s; ep:=e; //ep是这次应该扫的矩形多1的位置,因为和新生成的矩形是不用比的
050 while i<ep do
051 if(q[i].x2<kx1)or(q[i].x1>kx2)or
052 (q[i].y2<ky1)or(q[i].y1>ky2) //矩形相离
053 then inc(i)
054 else begin
055 f:=false;
056 wx1:=max(kx1,q[i].x1);
057 wy1:=max(ky1,q[i].y1);
058 wx2:=min(kx2,q[i].x2);
059 wy2:=min(ky2,q[i].y2);
060 if wy1>q[i].y1 then
061 begin
062 q[e].x1:=q[i].x1;
063 q[e].y1:=q[i].y1;
064 q[e].x2:=wx2;
065 q[e].y2:=wy1;
066 q[e].color:=q[i].color;
067 inc(e); f:=true;
068 end;
069 if wx1>q[i].x1 then
070 begin
071 q[e].x1:=q[i].x1;
072 q[e].y1:=wy1;
073 q[e].x2:=wx1;
074 q[e].y2:=q[i].y2;
075 q[e].color:=q[i].color;
076 inc(e); f:=true;
077 end;
078 if wy2<q[i].y2 then
079 begin
080 q[e].x1:=wx1;
081 q[e].y1:=wy2;
082 q[e].x2:=q[i].x2;
083 q[e].y2:=q[i].y2;
084 q[e].color:=q[i].color;
085 inc(e); f:=true;
086 end;
087 if wx2<q[i].x2 then
088 begin
089 q[e].x1:=wx2;
090 q[e].y1:=q[i].y1;
091 q[e].x2:=q[i].x2;
092 q[e].y2:=wy2;
093 q[e].color:=q[i].color;
094 inc(e); f:=true;
095 end;
096 if not f then //矩形出队就是把后面的矩形放上来
097 begin
098 dec(e); dec(ep);
099 q[i]:=q[ep]; q[ep]:=q[e];
100 dec(i); //新矩形覆盖原矩形的情况
101 end else begin
102 dec(e); q[i]:=q[e]; //没有覆盖的情况
103 end;
104 inc(i);
105 end;
106 q[e].x1:=kx1;
107 q[e].x2:=kx2;
108 q[e].y1:=ky1;
109 q[e].y2:=ky2;
110 q[e].color:=c;
111 inc(e); dec(n);
112 end;
113 close(input);
114
115 for i:=s to e-1 do
116 with q[i] do
117 inc(res[color],(x2-x1)*(y2-y1));
118
119 assign(output,'rect1.out'); rewrite(output);
120 for i:=1 to maxcolor do
121 if res[i]>0 then
122 writeln(i,' ',res[i]);
123 close(output);
124 end.
002 ID:xpycc1
003 PROG:rect1
004 LANG:PASCAL
005 }
006
007 program rect1;
008 const
009 maxcolor=2500;
010 maxq=100000;
011 type
012 squr=record
013 x1,x2,y1,y2,color:integer;
014 end;
015 var
016 res:array[1..maxcolor]of longint;
017 q:array[0..maxq]of squr;
018 n,rx2,ry2,wx1,wx2,wy1,wy2,c,kx1,ky1,kx2,ky2:integer;
019 s,e,ep,i:longint;
020 f:boolean;
021 //
022 function min(x,y:integer):integer;
023 begin
024 if x>y then min:=y
025 else min:=x;
026 end;
027 //
028 function max(x,y:integer):integer;
029 begin
030 if x>y then max:=x
031 else max:=y;
032 end;
033 //
034 begin
035 s:=0; e:=1;
036 assign(input,'rect1.in'); reset(input);
037 readln(rx2,ry2,n);
038 with q[s] do
039 begin
040 x1:=0;
041 x2:=rx2;
042 y1:=0;
043 y2:=ry2;
044 color:=1;
045 end;
046 while n>0 do
047 begin
048 readln(kx1,ky1,kx2,ky2,c);
049 i:=s; ep:=e; //ep是这次应该扫的矩形多1的位置,因为和新生成的矩形是不用比的
050 while i<ep do
051 if(q[i].x2<kx1)or(q[i].x1>kx2)or
052 (q[i].y2<ky1)or(q[i].y1>ky2) //矩形相离
053 then inc(i)
054 else begin
055 f:=false;
056 wx1:=max(kx1,q[i].x1);
057 wy1:=max(ky1,q[i].y1);
058 wx2:=min(kx2,q[i].x2);
059 wy2:=min(ky2,q[i].y2);
060 if wy1>q[i].y1 then
061 begin
062 q[e].x1:=q[i].x1;
063 q[e].y1:=q[i].y1;
064 q[e].x2:=wx2;
065 q[e].y2:=wy1;
066 q[e].color:=q[i].color;
067 inc(e); f:=true;
068 end;
069 if wx1>q[i].x1 then
070 begin
071 q[e].x1:=q[i].x1;
072 q[e].y1:=wy1;
073 q[e].x2:=wx1;
074 q[e].y2:=q[i].y2;
075 q[e].color:=q[i].color;
076 inc(e); f:=true;
077 end;
078 if wy2<q[i].y2 then
079 begin
080 q[e].x1:=wx1;
081 q[e].y1:=wy2;
082 q[e].x2:=q[i].x2;
083 q[e].y2:=q[i].y2;
084 q[e].color:=q[i].color;
085 inc(e); f:=true;
086 end;
087 if wx2<q[i].x2 then
088 begin
089 q[e].x1:=wx2;
090 q[e].y1:=q[i].y1;
091 q[e].x2:=q[i].x2;
092 q[e].y2:=wy2;
093 q[e].color:=q[i].color;
094 inc(e); f:=true;
095 end;
096 if not f then //矩形出队就是把后面的矩形放上来
097 begin
098 dec(e); dec(ep);
099 q[i]:=q[ep]; q[ep]:=q[e];
100 dec(i); //新矩形覆盖原矩形的情况
101 end else begin
102 dec(e); q[i]:=q[e]; //没有覆盖的情况
103 end;
104 inc(i);
105 end;
106 q[e].x1:=kx1;
107 q[e].x2:=kx2;
108 q[e].y1:=ky1;
109 q[e].y2:=ky2;
110 q[e].color:=c;
111 inc(e); dec(n);
112 end;
113 close(input);
114
115 for i:=s to e-1 do
116 with q[i] do
117 inc(res[color],(x2-x1)*(y2-y1));
118
119 assign(output,'rect1.out'); rewrite(output);
120 for i:=1 to maxcolor do
121 if res[i]>0 then
122 writeln(i,' ',res[i]);
123 close(output);
124 end.
所有评论,共0条:( 我也来说两句)
代码