ACM1198Farm Irrigation
这个题目好吓人呀!嘿嘿---
不过仔细分析下就可以啦!
#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的更多相关文章
- ZOJ 2412 Farm Irrigation
Farm Irrigation Time Limit: 2 Seconds Memory Limit: 65536 KB Benny has a spacious farm land to ...
- hdu.1198.Farm Irrigation(dfs +放大建图)
Farm Irrigation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU1198水管并查集Farm Irrigation
Benny has a spacious farm land to irrigate. The farm land is a rectangle, and is divided into a lot ...
- ZOJ 2412 Farm Irrigation(DFS 条件通讯块)
意甲冠军 两个农田管内可直接连接到壳体 他们将能够共享一个水源 有11种农田 管道的位置高于一定 一个农田矩阵 问至少须要多少水源 DFS的连通块问题 两个相邻农田的管道能够直接连接的 ...
- HDU 1198 Farm Irrigation (并检查集合 和 dfs两种实现)
Farm Irrigation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 【简单并查集】Farm Irrigation
Farm Irrigation Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tot ...
- Farm Irrigation
题目:Farm Irrigation 题目链接:http://210.34.193.66:8080/vj/Problem.jsp?pid=1494 题目思路:并查集 #include<stdio ...
- Farm Irrigation(非常有意思的并查集)
Farm Irrigation Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tot ...
- ZOJ2412 Farm Irrigation(农田灌溉) 搜索
Farm Irrigation Time Limit: 2 Seconds Memory Limit: 65536 KB Benny has a spacious farm land to ...
随机推荐
- (原) MaterialEditor部- UmateriaEditor中 Node编译过程和使用(3)
@author: 白袍小道 转载说明原处 插件同步在GITHUB: DaoZhang_XDZ 说明 1.本篇是接着-----(原) MaterialEditor部- UmateriaE ...
- mysql中的select语句where条件group by ,having , order by,limit的顺序及用法
-- 语法: SELECT select_list FROM table_name [ WHERE search_condition ] [ GROUP BY group_by_expression ...
- LeetCode 240——搜索二维矩阵 II
1. 题目 2. 解答 2.1. 方法一 从矩阵的左下角开始比较 目标值等于当前元素,返回 true: 目标值大于当前元素,j 增 1,向右查找,排除掉此列上边的数据(都比当前元素更小): 目标值小于 ...
- POJ 3348 Cows(凸包+多边形面积)
Description Your friend to the south is interested in building fences and turning plowshares into sw ...
- 衡量生活成本:消费者价格指数(CPI, Consumer Price Index)
经济学家应该如何把经济中的许多价格加总成一个单一指数,从而能够衡量价格的总体水平呢?他们可以简单地计算所有产品与服务价格的平均值,但是这种方法的不足之处是把所有的产品与服务等同处理.由于人们购买的鸡比 ...
- Switches and Lamps(思维)
You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This inform ...
- 软件工程 作业part1
自我介绍 老师您好,我叫宋雨,本科在长春理工大学,专业是计算机科学与技术. 1.回想一下你曾经对计算机专业的畅想:当初你是如何做出选择计算机专业的决定?你认为过去接触的课程是否符合你对计算机专业的期待 ...
- BluetoothSocket详解
一. BluetoothSocket简介 1. 简介 客户端与服务端 : BluetoothSocket 和 BluetoothServerSocket 类似于Java中的套接字的 Socket 和 ...
- android AndroidManifest.xml uses-feature 详解
如果你是一个Android用户,而且你有一个老旧的安装有android 1.5 的android设备,你可 能会注意到一些高版本的应用没有在手机上的Android Market 中显示.这必定是应用使 ...
- Java中I/O流之数据流
Java 中的数据流: 对于某问题:将一个 long 类型的数据写到文件中,有办法吗? 转字符串 → 通过 getbytes() 写进去,费劲,而且在此过程中 long 类型的数需要不断地转换. ...