zoukankan
html css js c++ java
补上以前没有AC的PKU儿八死三
额。。。DFS会RE。。。
#include
<
stdio.h
>
#include
<
string
.h
>
int
mmm[
1024
][
1024
];
int
rj[
1024
][
1024
];
int
cnt, N, M, i1, j1, i2, j2;
int
q[
1024
*
1024
][
2
];
const
int
dx[
4
]
=
{
1
,
0
,
-
1
,
0
}
;
const
int
dy[
4
]
=
{
0
,
1
,
0
,
-
1
}
;
void
BFS(
int
i,
int
j)
{
mmm[i][j]
=
1
;
int
front, rear, k;
q[
0
][
0
]
=
i;
q[
0
][
1
]
=
j;
for
(front
=
0
, rear
=
1
; front
<
rear; front
++
)
for
(k
=
0
; k
<
4
; k
++
)
{
i
=
q[front][
0
]
+
dx[k];
j
=
q[front][
1
]
+
dy[k];
if
((i
>=
i1
&&
i
<=
i2
&&
j
>=
j1
&&
j
<=
j2)
&&
mmm[i][j]
==
0
)
{
mmm[i][j]
=
1
;
q[rear][
0
]
=
i;
q[rear
++
][
1
]
=
j;
}
}
}
/**/
/*
void DFS(int i, int j)
{
mmm[i][j]=1;
if(i + 1 <= i2 && mmm[i + 1][j] == 0)
DFS(i + 1, j);
if(i - 1 >= i1 && mmm[i - 1][j] == 0)
DFS(i - 1, j);
if(j + 1 <= j2 && mmm[i][j + 1] == 0)
DFS(i, j + 1);
if(j - 1 >= j1 && mmm[i][j - 1] == 0)
DFS(i, j - 1);
}
*/
void
gra()
{
for
(
int
ii
=
i1; ii
<=
i2; ii
++
)
{
int
jj
=
j1;
while
( jj
<=
j2 )
{
while
(rj[ii][jj]
>
0
)
{
jj
=
rj[ii][jj];
if
(jj
>
j2)
break
;
}
if
(jj
>
j2)
break
;
if
( mmm[ii][jj]
==
0
)
{
//
DFS(ii, jj);
BFS(ii, jj);
cnt
++
;
}
jj
++
;
}
}
}
int
main()
{
scanf(
"
%d%d
"
,
&
N,
&
M);
for
(
int
i
=
0
; i
<
M; i
++
)
{
cnt
=
0
;
scanf(
"
%d%d%d%d
"
,
&
i1,
&
j1,
&
i2,
&
j2);
if
(j1
>
N) j1
=
N;
if
(j2
>
N) j2
=
N;
gra();
for
(
int
ci
=
i1; ci
<=
i2; ci
++
)
{
if
(rj[ci][j1]
<
j2
+
1
)
rj[ci][j1]
=
j2
+
1
;
}
printf(
"
%d\n
"
, cnt);
}
return
0
;
}
查看全文
相关阅读:
unix文件权限
jira部署,主机迁移,数据库迁移,jira
c函数习记
常用软介质下载
Matlab interpgui
LightOJ 1422
【CODEFORCES】 A. Keyboard
leetcode 230: Kth Smallest Element in a BST
Vertica7 Native Connection Load Balance
vlc模块间共享变量
原文地址:https://www.cnblogs.com/SQL/p/897785.html
最新文章
[AngularJS NG-redux] Handle Asynchronous Operations with Middleware
[AngualrJS NG-redux] Map State and Dispatchers to Redux
[Scss Flex] Reuse Flexbox Styles With A Sass Mixin
[Node.js] Testing ES6 Promises in Node.js using Mocha and Chai
Android——Cocosd2d-x手机游戏开发学习思路
poj 3628 (搜索or背包)
Hadoop: the definitive guide 第三版 拾遗 第十二章 之Hive初步
在线App开发平台——应用之星傻瓜式开发平台
weblogic开发模式与生产模式介绍
【oracle】触发器简单实现
热门文章
Asp.Net Design Pattern Studynotes -- Part1
zoj3329 One Person Game
JVM performance profiling (有待整理)
JavaScript面向对象继承方法
-lrt
c功能实战
jira破解
NetAddr
常用抓包指令for wireshark or tcpdump
libpcap/wwinpcap
Copyright © 2011-2022 走看看