nyoj92图像有用区域——BFS
2018-03-27 21:32
363 查看
图像有用区域
为什么不能AC…
为什么不能AC…
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <queue> #define maxn 1001 using namespace std; int W,H; int map[960][1440]; int Next[4][2] = {{0,1},{0,-1},{1,0},{-1,0}}; struct Node{ int x,y; Node(){} Node(int x,int y):x(x),y(y){} }; int ans = 0; void bfs(){ int nx,ny; queue <Node>que; que.push(Node(1,1)); map[1][1] = 0; while(!que.empty()){ Node head = que.front(); que.pop(); for(int k=0;k<4;k++){ nx = head.x + Next[k][0]; ny = head.y + Next[k][1]; if(nx>=1 && ny>=1 && nx<=H && ny<=W){ if(map[nx][ny]!=0){ map[nx][ny] = 0; que.push(Node(nx,ny)); } } } } } int main(){ // freopen("/Users/zhaohaibo/Desktop/a.txt","r",stdin); int ncase; cin>>ncase; while(ncase--){ memset(map,-1,sizeof(map)); cin>>W>>H; for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) scanf("%d",&map[i][j]); bfs(); for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) if(j==W) printf("%d\n",map[i][j]); else printf("%d ",map[i][j]); } return 0; }
相关文章推荐
- nyoj 92 图像有用区域 bfs
- NYOJ-92 图像有用区域(bfs)
- NYOJ 92 图像有用区域 【bfs】
- 【NYOJ-92- 图像有用区域-BFS】
- NYOJ 92--图像有用区域【BFS && 水题】
- NYOJ 92 图像有用区域(BFS)
- nyoj 92 图像有用区域 【bfs】
- NYOJ92 图像有用区域 【BFS】
- nyoj 92 图像有用区域 【BFS】 【好题 】
- NYOJ 92 图像有用区域 (经典的 bfs)
- nyoj92图像有用区域【bfs】
- nyoj--92 图像有用区域(bfs)
- NYOJ 92 图像有用区域(BFS)
- NYOJ 92 图像有用区域 (BFS)
- NYOJ 92 图像有用区域 bfs
- nyoj 图像有用区域(BFS)
- NYOJ 92 图像有用区域
- nyoj 图像有用区域(BFS)
- NYOJ92 图像实用区域 【BFS】
- NYOJ 92图像有用区域