【BZOJ】【P1102】【POI2007】【山峰和山谷Grz】【题解】【Flood Fill】
来源:互联网 发布:宋岳庭 知乎 编辑:程序博客网 时间:2024/05/01 09:55
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1102
水题不多说
Code:
#include<bits/stdc++.h>#define X first#define Y secondusing namespace std;typedef pair<int,int> pii;const int maxn=1005;int mp[maxn][maxn],n,ans1,ans2;bool vis[maxn][maxn];const int dx[8]={0,0,1,1,1,-1,-1,-1};const int dy[8]={1,-1,1,0,-1,1,0,-1};queue<pii>q;void bfs(int x,int y){vis[x][y]=1;int cnt1=0,cnt2=0;q.push(pii(x,y));while(!q.empty()){pii u=q.front();q.pop();for(int k=0;k<8;k++){x=u.X+dx[k],y=u.Y+dy[k];if(x<1||y<1||x>n||y>n)continue;if(mp[x][y]==mp[u.X][u.Y]&&!vis[x][y]){vis[x][y]=1;q.push(pii(x,y));}else{cnt1+=mp[x][y]>mp[u.X][u.Y];cnt2+=mp[x][y]<mp[u.X][u.Y];}}}ans1+=!cnt1&&cnt2;ans2+=!cnt2&&cnt1;}int main(){scanf("%d",&n);for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)scanf("%d",&mp[i][j]);for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(!vis[i][j])bfs(i,j);if(!ans1&&!ans2)ans1=ans2=1;printf("%d %d\n",ans1,ans2);return 0;}
0 0
- 【BZOJ】【P1102】【POI2007】【山峰和山谷Grz】【题解】【Flood Fill】
- 【BZOJ 1102】 [POI2007]山峰和山谷Grz
- [BZOJ]1102: [POI2007]山峰和山谷Grz
- BZOJ 1102 POI2007 山峰和山谷Grz Floodfill
- bzoj 1102: [POI2007]山峰和山谷Grz (floodfill)
- 【bzoj 1102】[POI2007]山峰和山谷Grz(BFS)
- BZOJ 1102: [POI2007]山峰和山谷Grz FloodFill 算法
- [POI2007] BZOJ 1102 山峰和山谷Grz-bfs-floodfill
- bzoj1102 [POI2007]山峰和山谷Grz
- [BZOJ1102] [POI2007]山峰和山谷Grz
- bzoj1102 [POI2007]山峰和山谷Grz floodfill
- 【bzoj1102】 [POI2007]山峰和山谷Grz
- [BZOJ1102][POI2007]山峰和山谷Grz(bfs:floodfill)
- Flood Fill
- flood fill
- 【BZOJ】【POI2007】【对称轴osi】【题解】【计算几何】
- 走迷宫 Flood Fill
- Flood fill 算法
- string查找
- 动态内存管理new&delete
- PullToRefresh扩展为上拉加载和下拉刷新
- Apriori Algorithm介绍及Python实现
- 水樹 奈々 Blog 20140922 これまでにない緊張感っ!译文
- 【BZOJ】【P1102】【POI2007】【山峰和山谷Grz】【题解】【Flood Fill】
- CRC32、MD5、SHA1算法校验介绍
- C语言_标准库中的流函数
- NYOJ 题目37 回文字符串(动态规划)
- .net signalR 实例
- Fibonacci函数递归实现
- 高并发Linux服务器的常用配置
- 开启与隐藏Android手机的开发者选项
- 求n的阶乘