这个题目好吓人呀!嘿嘿---

不过仔细分析下就可以啦!

 #include<iostream>
#include<cstring>
using namespace std;
const int N=;
int Gra[][]={
{,,,},{,,,},{,,,},{,,,},
{,,,},{,,,},{,,,},
{,,,},{,,,},{,,,},{,,,}};
int direction[][]={{-,},{,},{,},{,-}};
//11种铸造方式,1为开,0为关
//用输入的大写字母减去'A' 即可
//2和下面的0可相加
//3->1;0->2;1->3;
int m,n;//m lines and n characters
int map[N][N];
int vis[N][N];
void dfs(int x,int y)
{
vis[x][y]=;
for(int i=;i<;i++)
{
int X=x+direction[i][];
int Y=y+direction[i][];
int j=(i>=)?(i-):(i+);//顺序绝对不可以改,或者要改一起改,有点变动就是wrong
if(Gra[map[x][y]][i]&&<X&&X<=m&&<Y&&Y<=n)
{
if(!vis[X][Y]&&Gra[map[X][Y]][j])
dfs(X,Y);
}
}
}
int main()
{
char ch[N];
while(cin>>m>>n)
{
if(m<||n<)break;//exit;
memset(vis,,sizeof(vis));
for(int i=;i<=m;i++)
{
cin>>ch;
for(int j=;j<n;j++)
map[i][j+]=ch[j]-'A';
}
int count=;
for(int i=;i<=m;i++)
{
for(int j=;j<=n;j++)
if(!vis[i][j])
dfs(i,j),count++;
}
cout<<count<<endl;
}
return ;
}

ACM1198Farm Irrigation的更多相关文章

  1. ZOJ 2412 Farm Irrigation

    Farm Irrigation Time Limit: 2 Seconds      Memory Limit: 65536 KB Benny has a spacious farm land to ...

  2. hdu.1198.Farm Irrigation(dfs +放大建图)

    Farm Irrigation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. HDU1198水管并查集Farm Irrigation

    Benny has a spacious farm land to irrigate. The farm land is a rectangle, and is divided into a lot ...

  4. ZOJ 2412 Farm Irrigation(DFS 条件通讯块)

    意甲冠军  两个农田管内可直接连接到壳体  他们将能够共享一个水源   有11种农田  管道的位置高于一定  一个农田矩阵  问至少须要多少水源 DFS的连通块问题  两个相邻农田的管道能够直接连接的 ...

  5. HDU 1198 Farm Irrigation (并检查集合 和 dfs两种实现)

    Farm Irrigation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. 【简单并查集】Farm Irrigation

    Farm Irrigation Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tot ...

  7. Farm Irrigation

    题目:Farm Irrigation 题目链接:http://210.34.193.66:8080/vj/Problem.jsp?pid=1494 题目思路:并查集 #include<stdio ...

  8. Farm Irrigation(非常有意思的并查集)

    Farm Irrigation Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tot ...

  9. ZOJ2412 Farm Irrigation(农田灌溉) 搜索

    Farm Irrigation Time Limit: 2 Seconds      Memory Limit: 65536 KB Benny has a spacious farm land to ...

随机推荐

  1. 【转】unity3d 在UGUI中制作自适应调整大小的滚动布局控件

    转自 http://blog.csdn.net/rcfalcon/article/details/43459387 在游戏中,我们很多地方需要用到scroll content的概念:我们需要一个容器, ...

  2. BZOJ 3924 ZJOI2015 幻想乡战略游戏 树链剖分

    题目链接:https://www.luogu.org/problemnew/show/P3345(bzoj权限题) 题意概述:动态维护树的上所有点到这棵树的带权重心的距离和.N,Q<=10000 ...

  3. SPOJ 694 Distinct Substrings/SPOJ 705 New Distinct Substrings(后缀数组)

    Given a string, we need to find the total number of its distinct substrings. Input T- number of test ...

  4. Train Problem(栈的应用)

    Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of studen ...

  5. 软工2017第五周——个人PSP

    10.13 --10.19本周例行报告 1.PSP(personal software process )个人软件过程. 类型 任务 预计时间 开始时间                结束时间 中断时 ...

  6. 计算器软件实现系列(六)windowform窗体+SQL+策略模式

    一 整体概述 这个计算器软件的功能和以前的功能基本上一样,只不过是数据的保存形式发生了变化,,以前用的是txt文件保存,现在更正用SQL数据库,现在更改了以前的文件保存形式,是三层架构中数据层的更换, ...

  7. UVALive - 6868 Facility Locations 想法题

    题目链接: http://acm.hust.edu.cn/vjudge/problem/88634 Facility Locations Time Limit: 3000MS 题意 给你一个m*n的矩 ...

  8. 详解实现Android中实现View滑动的几种方式

    注: 本文提到的所有三种滑动方式的完整demo:ScrollDemo 1. 关于View我们需要知道的 (1)什么是View? Android中的View类是所有UI控件的基类(Base class) ...

  9. .net 内置对象之Session对象和Session的过期时间

    QQ:827969653 有需要的朋友可以下载Session类:SessionHelper类 http://technet.microsoft.com/zh-cn/library/system.web ...

  10. 数字证书认证这点事, SSL/TLS,OpenSSL

    1.概念 数字证书 HTTPS请求时,Server发给浏览器的认证数据,用私钥签名,并且告诉浏览器公钥,利用公钥解密签名,确认Server身份. 证书还会指明相应的CA,CA能确认证书是否真的是CA颁 ...