ACM-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吧!少年的更多相关文章
- “玲珑杯”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 对于样例, ...
- “玲珑杯”ACM比赛 Round #18 1147 - 最后你还是AK了(思维,边的贡献)
题目链接:http://www.ifrog.cc/acm/problem/1147 题解:这题很容易想到的是边的贡献也就是每条边最多被取到几次,和点的贡献类似,那些加边只要加在边贡献大的边上就行.然后 ...
- SCNU ACM 2016新生赛初赛 解题报告
新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...
- 【转】ACM博弈知识汇总
博弈知识汇总 转自:http://www.cnblogs.com/kuangbin/archive/2011/08/28/2156426.html 有一种很有意思的游戏,就是有物体若干堆,可以是火柴棍 ...
- 2016 ACM赛后总结
已经到6.30号了哎~ 比赛是6.5号的,被推迟了好久的总结现在发吧,因为我怕我再不写就真的会忘掉-- 6.3号晚,星期五,我们一行人乘坐 济南<->徐州 的火车,然后出发了-- 6.4号 ...
- Good Bye ACM
——记于2015.11.9 合肥 合肥区域赛结束了,长舒一口气,这次终于能成功退役了,以后可以不被学弟们吊打了Y(^_^)Y. 这次的比赛让我不禁联想起去年的上海现场赛,出题者防AK防得太过分了,又是 ...
- ACM博弈知识汇总(转)
博弈知识汇总 有一种很有意思的游戏,就是有物体若干堆,可以是火柴棍或是围棋子等等均可.两个人轮流从堆中取物体若干,规定最后取光物体者取胜.这是我国民间很古老的一个游戏,别看这游戏极其简单,却蕴含着深刻 ...
- 2014 ACM/ICPC 北京邀请赛 部分 题解
题目链接:http://acm.bnu.edu.cn/bnuoj/problem.php?search=2014+ACM-ICPC+Beijing+Invitational+Programming+C ...
- 手把手教你用C++ 写ACM自动刷题神器(冲入HDU首页)
转载注明原地址:http://blog.csdn.net/nk_test/article/details/49497017 少年,作为苦练ACM,通宵刷题的你 是不是想着有一天能够荣登各大OJ榜首,俯 ...
随机推荐
- layer弹出框包含页面
参考:http://www.cnblogs.com/zhengchenhui/p/6038865.html
- 小程序本地存储之wx.getStorageSync
这个主要可以解决微信小程序的记录缓存,入输入框的搜索历史记录 直接上代码 setsearchMsg:function(){ var that=this if (this.data.inputValue ...
- 如何关闭 Mac OS X EI Capitan 系统文件保护
在修改 Mac OS X EI Capitan 系统的某些系统文件的过程中,你可能会遇到即使你加了 sudo 以管理员身份去操作页会被拒绝, 这是一个名为 SIP(System Integrity P ...
- 一 Mybatis概述&与Hibernate的区别&CRUD
Mybatis是类似Hibernate的ORM持久层框架 为什么学习Mybatis? 是目前国内主流的持久层框架,面向sql(相较于Hibernate,Mybatis一定要用sql) Hibernat ...
- Myeclipse项目出现红叉解决方案
1.右键点击你的项目.选中properties 2.选中MyEclipse下的Project Facets里面的java 此时的版本号为1.5,修改 3.选中MyEclipse下的Project Fa ...
- CPU、内存、硬盘之间的关系
要完完全全地讲清楚cpu.内存.硬盘之间的关系,博客的篇幅是不够的.这里简单的介绍以下它们之间的关系,抛砖引玉. 1.CPU即中央处理器,是英语“Central Processing Unit”的缩写 ...
- C++ 11 :override 关键字的使用
override 关键字 作用:在成员函数声明或定义中, override 确保该函数为虚函数并覆写来自基类的虚函数. 位置:函数调用运算符之后,函数体或纯虚函数标识 "= 0" ...
- Codeforces 546 E:士兵的旅行 最大网络流
E. Soldier and Traveling time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Ubuntu下安装 Mysql
MYSQL在ubuntu16.04下的编译安装mysql-5.6.23.tar.gz 为减少安装过程中因权限带来个各种问题,建议全程用root用户编译安装,步骤如下: 1.安装依赖文件 apt-ge ...
- 用JS写一个网站树形菜单
先上效果图: 主体内容就是侧边展示的一二三级菜单,树形结构的. 前端页面布局内容,页面内容简单用ul li 来完成所有的罗列项.用先后顺序来区分一级二级三级: <body> <b&g ...