Program L 暴力求解
Description
Input
Output
Sample Input
1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0 题目大意:给出一个行列式,以‘@’为目标看它有几个连通块,输出其结果。
思路:连通块问题其实就是寻找可行解,将行列式全部
#include <iostream>
#include <cstdio>
#include <cstring>
const int maxn=100+5;
char s[maxn][maxn];
int bi_ji[maxn][maxn];
int m,n;
using namespace std;
void dfs(int r,int c,int d)
{
if(r<0||r>=m||c<0||c>=n)
return;
if(bi_ji[r][c]>0||s[r][c]!='@')
return;
bi_ji[r][c]=d;
for(int dr=-1;dr<=1;dr++)
for(int dc=-1;dc<=1;dc++)
if(dr!=0||dc!=0)
dfs(r+dr,c+dc,d);
}
int main()
{
int qu;
while(scanf("%d%d",&m,&n)==2&&m&&n)
{
memset(bi_ji,0,sizeof(bi_ji));
qu=0;
for(int i=0;i<m;i++)
scanf("%s",s[i]);
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
if(!bi_ji[i][j]&&s[i][j]=='@')
dfs(i,j,++qu);
printf("%d\n",qu);
}
return 0;
}
Program L 暴力求解的更多相关文章
- POJ 1562(L - 暴力求解、DFS)
油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...
- Program C 暴力求解
Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbers ...
- Program A - 暴力求解
Description Write a program that finds and displays all pairs of 5-digit numbers that between them ...
- Program B 暴力求解
Given a sequence of integers S = {S1,S2,...,Sn}, you should determine what is the value of the maxim ...
- 逆向暴力求解 538.D Weird Chess
11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...
- 隐型马尔科夫模型(HMM)向前算法实例讲解(暴力求解+代码实现)---盒子模型
先来解释一下HMM的向前算法: 前向后向算法是前向算法和后向算法的统称,这两个算法都可以用来求HMM观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...
- BestCoder Round #79 (div.2)-jrMz and angles,,暴力求解~
jrMz and angle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- hdu6570Wave (暴力求解)
Problem Description Avin is studying series. A series is called "wave" if the following co ...
- <字符串匹配>KMP算法为何比暴力求解的时间复杂度更低?
str表示文本串,m表示模式串; str[i+j] 和 m[j] 是正在进行匹配的字符; KMP的时间复杂度是O(m+n) , 暴力求解的时间复杂度是O(m*n) KMP利用了B[0:j]和A[i ...
随机推荐
- sqlserver 2008 服务器拒绝连接;拒绝访问指定的数据库
sqlserver配置管理器----sqlserver网络配置 --- 启用 named pipes OK 由于之前的程序是SQL2000开发的,迁移到SQL20008出了这个问题. 二 和主题没有什 ...
- C++ typedef 四个用途
第一.四个用途 用途一: 定义一种类型的别名,而不只是简单的宏替换.可以用作同时声明指针型的多个对象.比如:char* pa, pb; // 这多数不符合我们的意图,它只声明了一个指向字符变量的指针, ...
- 转:程序员最值得关注的10个C开源项目
程序员最值得关注的10个C开源项目 1. Webbench Webbench 是一个在 linux 下使用的非常简单的网站压测工具.它使用 fork ()模拟多个客户端同时访问我们设定的 URL,测试 ...
- 怎样使用ServletContextListener接口
ServletContext : 每一个web应用都有一个 ServletContext与之相关联. ServletContext对象在应用启动的被创建,在应用关闭的时候被销毁. ServletCon ...
- Mysql 组合查询 UNION 与 UNION ALL
- iOS AVAudioRecorder 录音频率、声道、位数配置 wav格式
iOS AVAudioRecorder 录音频率.声道.位数配置 #pragma mark 录音设置 - (void)setUP_VOICE_RECOARDER { NSError *error = ...
- 如何用腾讯云打造一款微视频APP
版权声明:本文由腾讯云原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/196 来源:腾云阁 https://www.qclo ...
- 理解Cookie和Session机制
转载: 理解Cookie和Session机制 会话(Session)跟踪是Web程序中常用的技术,用来跟踪用户的整个会话.常用的会话跟踪技术是Cookie与Session.Cookie通过在客户端记录 ...
- selenium+python笔记4
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 使用unittest组织用例 ""& ...
- hdu------(1757)A Simple Math Problem(简单矩阵快速幂)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...