题目描述:AK吧!少年

AK is an ACM competition finished all of the problems. AC This problem is one of the steps,so fight to AK。There are a number of graphics"_" and "#",In the graph,"#"make up "A" or "K" these two letters。Makea program to identify these letters, we want to kown the number of these twoletters.

输入

Input contains multiple test cases.
Each test case contains two integer N (10<=N<=100) and M (10<=M<=100) is the graphics of the number of rows and columns。
Next graphics, letter fonts and titles to describe these two letters the same standard fonts, letter size is not necessarily the same, and does not skew, each letter occupies a separate rectangular area itself is connected, do not cross, and other letters or connected.

输出

Each test case output the number of "A" and "K".

样例输入

10 47
_______________________________________________
_____________####________#####______###________
____________#######_______####_____###_________
___________###__###________###___#####_________
________#####____###_______###_###_____________
_________###______###______######______________
________##############_____###_###_____________
_______###__________###____###___###___________
______#####________####___###_____###__________
_____###______________###__###_______###_______

样例输出

1 1

思路:DFS判断图形即可。
#include "stdafx.h"
//AK吧,少年!
//解题思路:
//1.深搜或者广搜遍历
//2.遇到第一个合适的节点检查是“A”还是“K”,A和K的区别是x+1,y-1是不是#
//因为是一次遍历就遍历完全所有相连节点,所以只要判断符合条件的节点的特殊位置就可以判断是哪个字母 #include <stdio.h>
#include <string.h>
const int MAX = ;
int vis[MAX][MAX];
char map[MAX][MAX];
int dir[][] = { , , , -, , , -, , -, -, -, , , -, , };
int n, m,ans[]; void DFS(int x, int y)
{
vis[x][y] = ;
for (int i = ; i < ; i++)
{
int nx = dir[i][] + x;
int ny = dir[i][] + y;
if (nx >= && ny >= && nx < n && ny < m && !vis[nx][ny] && map[nx][ny] == '#')
{
DFS(nx, ny);
} }
} #include <iostream>
#include <queue>
using namespace std;
struct Point
{
int x, y;
};
queue<Point> q;
void BFS(int x, int y)
{
vis[x][y] = ;
Point p;
p.x = x;
p.y = y;
q.push(p);
while (!q.empty())
{
Point p = q.front();
q.pop();
int x = p.x;
int y = p.y;
vis[x][y] = ;
for (int i = ; i < n; i++)
{
int nx = dir[i][] + x;
int ny = dir[i][] + y;
if (nx >= && ny >= && nx < n && ny < m && !vis[nx][ny] && map[nx][ny] == '#')
{
Point p;
p.x = nx;
p.y = ny;
q.push(p);
}
} } } int check(int x, int y)
{
if (map[x + ][y - ] == '#') return ;
else return ;
} int main()
{
while (scanf("%d %d", &n, &m) != EOF)
{
memset(vis, , sizeof(vis));
memset(ans, , sizeof(ans));
for (int i = ; i < n; i++)
{
scanf("%s", map[i]);
}
for (int i = ; i < n; i++)
{
for (int j = ; j < m; j++)
{
if (!vis[i][j] && map[i][j] == '#')
{
//DFS(i, j);
BFS(i, j);
ans[check(i, j)] ++;
}
}
}
printf("%d %d\n", ans[], ans[]); }
return ;
}

ACM-AK吧!少年的更多相关文章

  1. “玲珑杯”ACM比赛 Round #18--最后你还是AK了(搜索+思维)

    题目链接   DESCRIPTION INPUT OUTPUT SAMPLE INPUT 1 4 2 1 2 5 2 3 5 3 4 5 5 5 SAMPLE OUTPUT 35 HINT 对于样例, ...

  2. “玲珑杯”ACM比赛 Round #18 1147 - 最后你还是AK了(思维,边的贡献)

    题目链接:http://www.ifrog.cc/acm/problem/1147 题解:这题很容易想到的是边的贡献也就是每条边最多被取到几次,和点的贡献类似,那些加边只要加在边贡献大的边上就行.然后 ...

  3. SCNU ACM 2016新生赛初赛 解题报告

    新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...

  4. 【转】ACM博弈知识汇总

    博弈知识汇总 转自:http://www.cnblogs.com/kuangbin/archive/2011/08/28/2156426.html 有一种很有意思的游戏,就是有物体若干堆,可以是火柴棍 ...

  5. 2016 ACM赛后总结

    已经到6.30号了哎~ 比赛是6.5号的,被推迟了好久的总结现在发吧,因为我怕我再不写就真的会忘掉-- 6.3号晚,星期五,我们一行人乘坐 济南<->徐州 的火车,然后出发了-- 6.4号 ...

  6. Good Bye ACM

    ——记于2015.11.9 合肥 合肥区域赛结束了,长舒一口气,这次终于能成功退役了,以后可以不被学弟们吊打了Y(^_^)Y. 这次的比赛让我不禁联想起去年的上海现场赛,出题者防AK防得太过分了,又是 ...

  7. ACM博弈知识汇总(转)

    博弈知识汇总 有一种很有意思的游戏,就是有物体若干堆,可以是火柴棍或是围棋子等等均可.两个人轮流从堆中取物体若干,规定最后取光物体者取胜.这是我国民间很古老的一个游戏,别看这游戏极其简单,却蕴含着深刻 ...

  8. 2014 ACM/ICPC 北京邀请赛 部分 题解

    题目链接:http://acm.bnu.edu.cn/bnuoj/problem.php?search=2014+ACM-ICPC+Beijing+Invitational+Programming+C ...

  9. 手把手教你用C++ 写ACM自动刷题神器(冲入HDU首页)

    转载注明原地址:http://blog.csdn.net/nk_test/article/details/49497017 少年,作为苦练ACM,通宵刷题的你 是不是想着有一天能够荣登各大OJ榜首,俯 ...

随机推荐

  1. 01背包问题_回溯法&分支限界法

    package 分支限界法; import java.util.LinkedList; import java.util.Scanner; /*01背包问题*/ public class ZOPack ...

  2. SpringCloud实战——(2)通过Feign调用其他模块

    大型项目下往往有很多模块,ZCGL项目结构如下: 需要引用的其他模块已经发布成服务并在Eureka Server注册中心注册,如下: 写程序时引用了其他模块,并且其他模块在项目中,但是IDEA任然无法 ...

  3. div 浮动

    浮动 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <titl ...

  4. 浏览器之本地缓存存储 localStorage 和 sessionStorage的区别以及用法

    区别: localStorage永久保存在浏览器  :sessionStorage在浏览器关闭之后存储的数据就会销毁 用法:两者用法差不多,但是取值有所不同 编辑页面逻辑代码为: 这是给 id=btn ...

  5. java中将图片上传到配置好的ftp服务器上

    测试用例: @Test public void testFtp() throws Exception { //1.连接ftp服务器 FTPClient ftpClient = new FTPClien ...

  6. jquery源码部分分析

    1.整体架构和如何辨别浏览器端和node端 自执行函数,判断在什么端,如果在浏览器端就执行factory函数 //(function(){a,b})(a,b) //jq大架构,闭包,自执行函数,传入函 ...

  7. IOS UIKIT_EXTERN, __attribute__((visibility ("default"))) 是啥玩意?

    问题提出 在学习IOS时候,碰到一个函数NSStringFromCGPoint (UIGeometry.h) 其原型是 UIKIT_EXTERN NSString *NSStringFromCGPoi ...

  8. 玩玩负载均衡---在window与linux下配置nginx

      最近有些时间,开始接触负载均衡方面的东西,从硬件F5再到Citrix Netscalar.不过因为硬件的配置虽然不复杂,但昂贵的价格也让一般用户望而却步(十几万到几十万),所以只能转向nginx, ...

  9. C++ Primer Plus 6 笔记(3)

    第5章 1.cout在显示bool值之前将它们转换为int,但cout.setf(ios:: boolalpha)函数调用设置了一个标记,该标记命令cout显示true和false,而不是1和0 2. ...

  10. VUE - 使用axios数据请求时数据绑定时 报错 TypeError: Cannot set property 'xxxx' of undefined 的解决办法

     created() {     var that=this     axios.get('http://jsonplaceholder.typicode.com/todos')     .then( ...