Farm Irrigation HDU
来源:互联网 发布:windows模拟器 编辑:程序博客网 时间:2024/06/08 07:43
点击打开链接
没什么道道 就是麻烦 要仔细
看每个块是什么类型 又能和什么类型的块相连 预处理一下即可
#include <bits/stdc++.h>using namespace std;struct node{ int dir[4];};node per[11];int mp[100][100];int f[5000];int n,m;void init();void calculate();void unite(int u,int v);int getf(int p);int main(){ int k; int i,j,sum; char ch[100]; init(); while(scanf("%d%d",&n,&m)!=EOF) { if(n<0||m<0) break; for(i=1;i<=n;i++) { scanf("%s",ch); for(j=0;j<m;j++) { mp[i][j+1]=ch[j]-'A'; } } for(i=1;i<=n*m;i++) { f[i]=i; } calculate(); sum=0; for(i=1;i<=n*m;i++) { if(f[i]==i) sum++; } printf("%d\n",sum); } return 0;}void init(){ per[0].dir[0]=1, per[0].dir[1]=1, per[0].dir[2]=0, per[0].dir[3]=0; per[1].dir[0]=0, per[1].dir[1]=1, per[1].dir[2]=1, per[1].dir[3]=0; per[2].dir[0]=1, per[2].dir[1]=0, per[2].dir[2]=0, per[2].dir[3]=1; per[3].dir[0]=0, per[3].dir[1]=0, per[3].dir[2]=1, per[3].dir[3]=1; per[4].dir[0]=0, per[4].dir[1]=1, per[4].dir[2]=0, per[4].dir[3]=1; per[5].dir[0]=1, per[5].dir[1]=0, per[5].dir[2]=1, per[5].dir[3]=0; per[6].dir[0]=1, per[6].dir[1]=1, per[6].dir[2]=1, per[6].dir[3]=0; per[7].dir[0]=1, per[7].dir[1]=1, per[7].dir[2]=0, per[7].dir[3]=1; per[8].dir[0]=1, per[8].dir[1]=0, per[8].dir[2]=1, per[8].dir[3]=1; per[9].dir[0]=0, per[9].dir[1]=1, per[9].dir[2]=1, per[9].dir[3]=1; per[10].dir[0]=1, per[10].dir[1]=1, per[10].dir[2]=1, per[10].dir[3]=1; return;}void calculate(){ int next[4][2]={0,-1,-1,0,0,1,1,0}; int i,j,k,tx,ty; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { for(k=0;k<4;k++) { tx=i+next[k][0]; ty=j+next[k][1]; if(1<=tx&&tx<=n&&1<=ty&&ty<=m) { //printf(" ***%d %d %c %c %d %d*** ",k,(k+2)%2,mp[tx][ty]+'A',mp[i][j]+'A',per[mp[tx][ty]].dir[(k+2)%2],per[mp[i][j]].dir[k]); if(per[mp[tx][ty]].dir[(k+2)%4]&&per[mp[i][j]].dir[k]) { unite((tx-1)*m+ty,(i-1)*m+j); } } } } //printf("\n"); } return;}void unite(int u,int v){ int fu,fv; fu=getf(u); fv=getf(v); if(fu!=fv) { f[fv]=fu; } return;}int getf(int p){ if(f[p]==p) return p; else { f[p]=getf(f[p]); return f[p]; }}
阅读全文
0 0
- 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
- hdu 1198 Farm Irrigation
- CRF++在linxu下的使用
- enum
- elasticsearch 5.6 安装
- h264中的ipb帧
- Python sorted
- Farm Irrigation HDU
- 素数
- Linux下快速定位日志
- Spring Boot:(四)统一日志处理
- C++中的argc和argv
- 【Python】【矩阵】协方差矩阵;特征值;特征向量
- HDU-3371 Connect the Cities
- 动态测试方法运行时间的工具BTrace的简单应用
- shell 函数 返回值