HDU 1198 Farm Irrigation 并查集
来源:互联网 发布:亚马逊读书软件 编辑:程序博客网 时间:2024/05/22 04:25
自己思路和答案思路一样这种事情最开心啦~其实不看答案自己应该也能改对 又是把行列搞反了
#include <iostream>#include<cstdio>#include<cstring>using namespace std;bool type[15][4]={{1,0,0,1},{1,1,0,0},{0,0,1,1},{0,1,1,0},{1,0,1,0},{0,1,0,1},{1,1,0,1},{1,0,1,1},{0,1,1,1},{1,1,1,0},{1,1,1,1}};int f[300000],n,m;char c;int num[100][100];void init(int n){ for(int i=1;i<=n;i++) f[i]=i;}int find(int x){ if(x==f[x]) return x; int tmp=f[x]; f[x]=find(f[x]); return f[x];}int main(){ //freopen("cin.txt","r",stdin); while(~scanf("%d%d",&m,&n)) { if(m==-1&&n==-1) break; init(n*m); for(int i=1;i<=m;i++) { for(int j=1;j<=n;j++) { cin>>c; num[i][j]=c-65; //cout<<num[i][j]<<" "; } // cout<<endl; } int count=n*m; for(int i=1;i<=m;i++) for(int j=1;j<n;j++) { if(type[num[i][j]][1]&&type[num[i][j+1]][3]) { int fx=find(i*n-n+j),fy=find(i*n-n+j+1); if(fx!=fy) {f[fx]=fy;count--;} } } for(int i=1;i<=n;i++) for(int j=1;j<m;j++) { if(type[num[j][i]][2]&&type[num[j+1][i]][0])//就是这里 这里这里~~ { int fx=find(j*n-n+i),fy=find(j*n+i); if(fx!=fy) {f[fx]=fy;count--;} } } cout<<count<<endl; } return 0;}
0 0
- hdu 1198 Farm Irrigation(并查集)
- hdu 1198 Farm Irrigation( 并查集)
- HDU 1198 Farm Irrigation(并查集)
- HDU 1198 Farm Irrigation 【并查集】
- HDU 1198Farm Irrigation(并查集)
- HDU 1198 Farm Irrigation(并查集)
- hdu 1198 Farm Irrigation(并查集)
- hdu 1198 Farm Irrigation(并查集)
- HDU 1198 Farm Irrigation 并查集
- HDU 1198 Farm Irrigation 并查集
- hdu-1198-Farm Irrigation(并查集)
- HDU 1198 Farm Irrigation (并查集)
- HDU 1198 Farm Irrigation 并查集
- hdu 1198 Farm Irrigation 并查集
- hdu 1198 Farm Irrigation(搜索+并查集)
- hdu 1198 Farm Irrigation (并查集)
- HDU 1198 Farm Irrigation 并查集+枚举
- hdu 1198 Farm Irrigation(并查集)
- leetcode Valid Parentheses 有效括号
- jlink_for_linux
- html借助一般处理程序实现文件上传到服务器
- Ubuntu下搜狗输入的安装
- [leetcode-92]Reverse Linked List II(c++)
- HDU 1198 Farm Irrigation 并查集
- 第16章 进程、应用程序域和对象上下文
- valgrind+kvalgrind
- 漫谈程序员(一)程序员未来发展三大方向
- SAP服务器性能管理常用的功能解析
- flex bison 笔记
- cygwin和mingw的区别
- 4.2 设计具有背景图的按钮---ImageButton的焦点以及事件的处理
- tarjan算法求强连通分量