题目描述: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. jmeter实现文件下载

    通过浏览器下载文件时,会提示选择保存路径,但是利用测试工具jmeter请求时,在页面看到请求次数是增加了,而本地没有具体下载下来的文件. 需要在具体的文件下载请求下面,添加后置处理器-bean she ...

  2. Ubuntu 安装MySQL并打开远程连接

    首先使用su命令切换到root账户 在用apt-get install mysql-server命令获取到MySQL的服务 等待下载安装,按照提示输入MySQL的密码 安装完成后对mysqld.cnf ...

  3. 【剑指Offer面试编程题】题目1504:把数组排成最小的数--九度OJ

    题目描述: 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个.例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323. 输入: 输 ...

  4. 与Python的第一次见面

    1.Python的起源 Python的作者,Guido von Rossum,确实是荷兰人.1982年,Guido从阿姆斯特丹大学(University of Amsterdam)获得了数学和计算机硕 ...

  5. Android 获取当前日期距离过期时间的日期差值的完整方法直接使用

    /*** * 获取当前日期距离过期时间的日期差值 * @param endTime * @return */public String dateDiff(String endTime) { Strin ...

  6. Ajax接收Json数据,调用template模板循环渲染页面的方法

    一. 后台接口吐出JSON数据 后台php接口中,需要写三个部分: 1.1 开头header规定数据格式: header("content-type:application/json;cha ...

  7. Android中ListView结合CheckBox判断选中项

    本文主要实现在自定义的ListView布局中加入CheckBox控件,通过判断用户是否选中CheckBox来对ListView的选中项进行相应的操作.通过一个Demo来展示该功能,选中ListView ...

  8. Time Series_1_BRKA Case

    Berkshire Hathaway (The most expensive stock ever in the world) 1.1 Download data require(quantmod) ...

  9. query.locate过个过滤参数

    需要引用Variants locate( 'typeid;name',vararrayof([key1,key2]),[]);

  10. Vue项目中v-for无法渲染数据

    在Vue项目中,我们想要实现下面的布局效果 后端返回的数据格式如下,可以看出产品列表五张图的数据位于同一个数组中 而我的html结构如下: 我希望直接渲染左边一张大图,然后右边的四张小图通过v-for ...