暑假训练之记录
ACM/ICPC
PKU 3338 Rectangle Cutting
比较烦人的模拟
1
#include
<
stdio.h
>
2
#include
<
string
.h
>
3
char
xy[
30
][
30
],yx[
30
][
30
],use[
30
][
30
];
4
int
n,m;
5
void
di(
int
x,
int
y)
6
{
7
if
(x
>=
m
||
y
>=
n)
return
;
8
use[x][y]
=
0
;
9
//
printf("%d %d\n",x,y);
10
if
(xy[x][y
+
1
]
&&
use[x
-
1
][y])di(x
-
1
,y);
11
if
(xy[x
+
1
][y
+
1
]
&&
use[x
+
1
][y])di(x
+
1
,y);
12
if
(yx[y
+
1
][x
+
1
]
&&
use[x][y
+
1
])di(x,y
+
1
);
13
if
(yx[y][x
+
1
]
&&
use[x][y
-
1
])di(x,y
-
1
);
14
}
15
int
main()
16
{
17
int
ans,i,k,x1,x2,y1,y2,t,j;
18
while
(scanf(
"
%d%d
"
,
&
n,
&
m),n)
19
{
20
memset(xy,
1
,
sizeof
(xy));
21
memset(use,
1
,
sizeof
(use));
22
memset(yx,
1
,
sizeof
(yx));
23
ans
=
0
;
24
for
(i
=
1
;i
<=
m;i
++
)yx[
0
][i]
=
0
;
25
for
(i
=
1
;i
<=
m;i
++
)yx[n][i]
=
0
;
26
for
(i
=
1
;i
<=
n;i
++
)xy[
0
][i]
=
0
;
27
for
(i
=
1
;i
<=
n;i
++
)xy[m][i]
=
0
;
28
scanf(
"
%d
"
,
&
k);
29
while
(k
--
)
30
{
31
scanf(
"
%d%d%d%d
"
,
&
x1,
&
y1,
&
x2,
&
y2);
32
if
(x1
>
x2)
{t
=
x1;x1
=
x2;x2
=
t;}
33
if
(y1
>
y2)
{t
=
y1;y1
=
y2;y2
=
t;}
34
//
printf("asdasdasdas%d %d\n",x1,y1);
35
for
(i
=
y1
+
1
;i
<=
y2;i
++
)xy[x1][i]
=
0
;
36
for
(i
=
y1
+
1
;i
<=
y2;i
++
)xy[x2][i]
=
0
;
37
for
(i
=
x1
+
1
;i
<=
x2;i
++
)yx[y1][i]
=
0
;
38
for
(i
=
x1
+
1
;i
<=
x2;i
++
)yx[y2][i]
=
0
;
39
}
40
//
printf("asdasdasdas%d\n",xy[1][1]);
41
for
(i
=
0
;i
<
m;i
++
)
42
for
(j
=
0
;j
<
n;j
++
)
43
{
44
if
(use[i][j]
&&
(xy[i][j
+
1
]
||
xy[i
+
1
][j
+
1
]
||
yx[j][i
+
1
]
||
yx[j
+
1
][i
+
1
]))
45
{
46
//
printf("******************\n");
47
di(i,j);
48
ans
++
;
49
}
50
}
51
for
(i
=
0
;i
<
m;i
++
)
52
for
(j
=
0
;j
<
n;j
++
)
if
(use[i][j])ans
++
;
53
printf(
"
%d\n
"
,ans);
54
55
}
56
return
0
;
57
}
58
59
posted on 2008-07-18 16:46
gong
阅读(192)
评论(0)
编辑
收藏
引用
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
博客园最新博文
博问
管理
Powered by:
C++博客
Copyright © gong
<
2008年7月
>
日
一
二
三
四
五
六
29
30
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
1
2
3
4
5
6
7
8
9
导航
C++博客
首页
新随笔
联系
聚合
管理
统计
随笔 - 50
文章 - 0
评论 - 22
引用 - 0
常用链接
我的随笔
我的评论
我参与的随笔
留言簿
(6)
给我留言
查看公开留言
查看私人留言
随笔档案
2009年7月 (11)
2008年8月 (1)
2008年7月 (38)
搜索
积分与排名
积分 - 29954
排名 - 669
最新评论
1. re: uva :: Programming Challenges :: Chapter 1-10189 - Minesweeper
那个P[8][2]是怎么想到的呢?
--陈泓旭
2. re: TOJ 2870 The K-th City 解题
哥们儿,我才识学浅,不是太理解,你这是dijkstra算法吗? 还是动态规划之类的?
--HereIcan
3. re: TOJ 2870 The K-th City 解题
aaa
--HereIcan
4. re: PKU 3367 Expressions 题解
I think we can help each other,make friends with you.(QQ:1015380720)
--ahshua
5. re: TJU 2094 Reserve Bookshelf 题解
在我们学校的oj上面提交返回错误啊
--夜雨
阅读排行榜
1. Toj Lawrence of Arabia 四边形不等式优化(1643)
2. PKU 1160 Post Office(1405)
3. uva :: Programming Challenges :: Chapter 1-10137 - The Trip(1266)
4. TOJ 2553 Japan (1215)
5. PKU 3370 Halloween treats 题解(1192)
评论排行榜
1. PKU 3337 Expression Evaluator(4)
2. Toj Lawrence of Arabia 四边形不等式优化(4)
3. TOJ 2870 The K-th City 解题(2)
4. PKU 3370 Halloween treats 题解(2)
5. TJU 2094 Reserve Bookshelf 题解(2)