HDU 1198 Farm Irrigation(搜索)
来源:互联网 发布:知乎经典问答 感人 编辑:程序博客网 时间:2024/06/06 19:28
题意:A-K分别代表不同的水管接口,问有多少个不联通的水管。
思路:暴搜
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <queue>using namespace std;const int N = 59;int n,m;char map[N][N];int num[]={2,2,2,2,2,2,3,3,3,3,4};int mm[][5]={ {0,1}, {0,3}, {1,2}, {2,3}, {0,2}, {1,3}, {0,1,3}, {0,1,2}, {1,2,3}, {0,2,3}, {0,1,2,3}};void init(){ for(int i=1;i<=n;i++) scanf("%s",map[i]+1);}bool oor(int x,int y){ if(x<1||x>n) return false; if(y<1||y>m) return false; return true;}int dx[] ={-1,0,1,0};int dy[] ={0,-1,0,1};void dfs(int x,int y){ if(!oor(x,y)||map[x][y]=='O') return ; //cout<<x<<" "<<y<<endl; int k = map[x][y]-'A'; map[x][y] = 'O'; for(int i=0;i<num[k];i++) { int tx = x+dx[mm[k][i]],ty = y+dy[mm[k][i]]; if(!oor(tx,ty)||map[tx][ty]=='O') continue; int kk=map[tx][ty]-'A'; //cout<<"* "<<tx<<" "<<ty<<endl; for(int j=0;j<num[kk];j++) if((mm[k][i]!=mm[kk][j])&&((mm[k][i]+mm[kk][j])%2)==0) dfs(tx,ty); }}void solve(){ int ans=0; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(map[i][j]!='O') dfs(i,j),ans++; printf("%d\n",ans);}int main(){ freopen("in.txt","r",stdin); while(~scanf("%d%d",&n,&m)&&(n+m)>=0) { init(); solve(); } return 0;}
- HDU 1198 Farm Irrigation(搜索)
- 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
- 基础(暴露元数据交换节点)
- dedecms V5.6 批量提取第一个图片作为缩略图(支持文章和图集模型
- 软件设计中的原则(GRASP)
- vs2010 无法连接到asp.net development server
- xpath和htmlparser的配合使用
- HDU 1198 Farm Irrigation(搜索)
- MotioninJoy安装教程-版本0.6.0003
- DEDECMS批量重新提取缩略图
- 用WIN7自带分区工具分区
- 基础(服务寄宿在IIS中)
- 特殊对象this
- 多层架构解析
- 老鼠与毒药
- 微软亚洲研究院新推英库拼音输入法