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榜首,俯 ...
随机推荐
- user模块User表
user模块User表 创建user模块 前提:在 luffy 虚拟环境下 1.终端从项目根目录进入apps目录 >: cd luffyapi & cd apps 2.创建app > ...
- json object string互转
参考: https://www.cnblogs.com/guangshan/p/4459436.html JsonArray和JsonObject遍历方法 参考:https://blog.csdn.n ...
- IdentityServer4专题之三:OAuth、SSO和OpenID
一.oauth 典型案例:如果一个用户R拥有两项服务:一项服务是图片在线存储服务A,另一个是图片在线打印服务B.由于服务A与服务B是由两家不同的服务提供商提供的,所以用户在这两家服务提供商的网站上各自 ...
- 写给java web一年左右工作经验的人
摘要 大学就开始学习web,磕磕绊绊一路走过来,当中得到过开源社区很多的帮助,总结了这些年来的技术积累,回馈给开源社区. ps:图片都是从网上盗...感谢原作者. ps:文字千真万确都是我自己写的 ...
- C# 创建Windows Service(Windows服务)程序
本文介绍了如何用C#创建.安装.启动.监控.卸载简单的Windows Service 的内容步骤和注意事项. 一.创建一个Windows Service 1)创建Windows Service项目 2 ...
- 题解 CF1131C 【Birthday】
CF大水题 题意:给你n个人,他们的身高是a[i],让你将这几个人排成一个环,使得他们两两之间身高差的和最小. 思路:简单到爆了,恶意评分上蓝.直接将那几个人排个序,然后按序左右放就行了,也就是说1号 ...
- 动态、指针field-symbols初探
DATA: BEGIN OF STRUC, COMP1 VALUE ', COMP2 VALUE ', COMP3 TYPE STRING VALUE 'bruce king', END OF STR ...
- Ternsorflow 学习:000-在 Ubuntu 16.04 上安装并使用 TensorFlow_v1.14 (改)
声明:本人已经对原文链接根据情况做出合理的改动. 本系列文章使用的是Tensorflow v1.14 引言 TensorFlow 是由谷歌构建的用于训练神经网络的开源机器学习软件.TensorFlow ...
- P1067 试密码
P1067 试密码 转跳点:
- ubuntu18.04窗口截图和选区截图快捷键
解决方法: 1.点击左下角的系统设置. 2.点击设备. 3.点击键盘,可查看各种截图操作的快捷键. PS:双击图中的快捷键可以设置新的快捷键.