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榜首,俯 ...
随机推荐
- Django:使用django自带的登录模块登录后会默认登录到 /accounts/profile 下的问题
django settings中LOGIN_REDIRECT_URL默认重定向到/accounts/profile下,可通过配置修改
- Android示例程序剖析之记事本(一)
Android SDK提供了很多示例程序,从这些示例代码的阅读和试验中能够学习到很多知识.本系列就是要剖析Android记事本示例程序,用意就是一步步跟着实例进行动手操作,在实践中体会和学习Andro ...
- centos8 安装mysql 8.0
本文参照:https://blog.csdn.net/qq_43232506/article/details/102816659 • 安装mysql及依赖 dnf install @mysql • ...
- Android:用代码修改一行文字中某几个字的颜色
TextView changeVideoQualityTxt = (TextView) rootView.findViewById(R.id.enter_wireless_display_txt); ...
- CentOS 下 安装 nginx 执行配置命令 ./configure 报错
CentOS 下 安装 nginx 执行配置命令 ./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx 时提示以下错误: checkin ...
- 工作中一些常用的linux命令
问题一: 绝对路径用什么符号表示?当前目录.上层目录用什么表示?主目录用什么表示? 切换目录用什么命令? 答案:绝对路径:如/etc/init.d当前目录和上层目录:./ ../主目录:~/切换目录 ...
- 三 Hibernate持久化状态&主键生成策略
持久化类 持久化:将内存中的一个对象持久化到数据库中的过程 持久化类:Java类+映射文件.Java中一个类与数据库的表建立了映射关系,那么这个类称为持久化类. 持久化类的编写规则: 对持久化类提供一 ...
- 攻防世界--web新手练习区(1)
1. 题目描述:X老师想让小明同学查看一个网页的源代码,但小明却发现鼠标右键不管用了. http://111.198.29.45:53629 通过阅读题目描述分析,我们需要查看源码,但是鼠标右键 ...
- swoole之建立 websocket server
一.代码部分 <?php /** * 为什么用WebSocket? * HTTP的通信只能由客户端发起 * * WebSocket 协议是基于TCP的一种新的网络协议.实现了浏览器与服务器全双工 ...
- Unix-Time
1. Unix_time 2. Year_2000_problem 3. Year_10,000_problem 4. Year_2038_problem 5. Time_formatting_and ...