1091. Acute Stroke (30)--BFS数多少块儿
2018-03-08 13:43
417 查看
#include <cstdio> #include <cstdlib> #include <iostream> #include <algorithm> #include <cmath> #include <string> #include <cstring> #include <vector> #include <queue> #include <map> #include <set> #include <stack> using namespace std; struct node { int x,y,z; }; int N,M,L,T; int g[2000][200][100]={0}; int book[2000][200][100]={0}; int X[6]={1,-1,0,0,0,0}; int Y[6]={0,0,1,-1,0,0}; int Z[6]={0,0,0,0,1,-1}; bool judge(node a) { int x=a.x; int y=a.y; int z=a.z; if( (x<0||y<0||z<0)||(x>=M||y>=N||z>=L) )//出界 return 0; if(g[x][y][z]==0)//点是0 return 0; if(book[x][y][z]==1)//已被访问过 return 0; return 1; } int bfs(int x,int y,int z) { int cou=0; book[x][y][z]=1;//原点先标记 cou++; node tnode;//搜索的元素 tnode.x=x; tnode.y=y; tnode.z=z; queue<node> q; q.push(tnode); while(!q.empty()) { for(int i=0;i<6;i++) { int nx=q.front().x+X[i]; int ny=q.front().y+Y[i]; int nz=q.front().z+Z[i]; node tnode2;//周围的node tnode2.x=nx; tnode2.y=ny; tnode2.z=nz; if(judge(tnode2)==1) { q.push(tnode2); book[nx][ny][nz]=1; cou++; } } q.pop(); } return cou; } int main() { // freopen("in.txt","r",stdin); scanf("%d %d %d %d",&M,&N,&L,&T); for(int k=0;k<L;k++) { for(int i=0;i<M;i++) { for(int j=0;j<N;j++) { scanf("%d",&g[i][j][k]); } } } int ans=0; for(int k=0;k<L;k++) { for(int i=0;i<M;i++) { for(int j=0;j<N;j++) { if(g[i][j][k]==1&&book[i][j][k]==0) { int cou=bfs(i,j,k);//对每个点进行搜索 if(cou>=T) { ans+=cou; } } } } } printf("%d",ans); return 0; }
相关文章推荐
- 鸡兔共笼,共有30个头和90只脚,求鸡兔各有多少?
- PAT - 甲级 - 1091. Acute Stroke (30)(三维BFS)
- PAT甲题题解-1091. Acute Stroke (30)-BFS
- 1127. ZigZagging on a Tree (30)[二叉树构建-dfs-bfs]
- 1004. Counting Leaves (30)(*****dfs/bfs)
- 1076. Forwards on Weibo (30) - 记录层的BFS改进
- PAT - 甲级 - 1076. Forwards on Weibo (30)(BFS)
- 7-10 六度空间(30 分)(bfs)
- 1076. Forwards on Weibo (30) - 记录层的BFS改进
- 1076. Forwards on Weibo (30)-PAT甲级真题(图的遍历bfs)
- PAT--1091. Acute Stroke (30)(三维bfs)
- 用十进制计算30!(30的阶乘),将结果转化成3进制进行表示的话,该进制下的结果末尾会有多少个0?
- 浙大pat 牛客网 1011 Forwards on Weibo (30) BFS
- 07-图5 Saving James Bond - Hard Version(30 分)BFS记录路径
- PAT 1131. Subway Map (30) 地铁换乘,优先BFS搜图应用
- C++ 编程百例30(2) 第100002(十万零二)个素数是多少
- /23 /24 /26/28 /29 /30或10.0.0.1/29这样怎么算服务器IP数是多少?
- 1076. Forwards on Weibo (30)--和层数有关的最好用bfs,用dfs容易不然出现短路或者环的情况
- 1004. Counting Leaves (30) 树的遍历 DFS BFS
- PAT (Advanced Level) 1004. Counting Leaves (30) BFS