HDU1312 Red and Black 解读
递归搜索方法标题,采用递归搜索方法,但是,如果没有迭代计算的真正的政党格。
我们的想法是:
1 每一个搜索为党格要改变电流方向格的值至 ‘*’,或任何其他非'.'的值,代表方格了
2 递归的时候不回复这个方格的值,就实际上不用反复搜索这个方格了。故此不用回溯
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int R, C, blacks;
vector<string> board; inline bool isLegal(int r, int c)
{
return r>=0 && c>=0 && r<R && c<C && board[r][c] == '.';
} void getBlacks(int r, int c)
{
blacks++;
board[r][c] = '*';
if (isLegal(r-1, c)) getBlacks(r-1, c);
if (isLegal(r+1, c)) getBlacks(r+1, c);
if (isLegal(r, c-1)) getBlacks(r, c-1);
if (isLegal(r, c+1)) getBlacks(r, c+1);
} int main()
{
string s;
while (cin>>C>>R && C)
{
board.clear();
for (int i = 0; i < R; i++)
{
cin>>s;
board.push_back(s);
}
blacks = 0;
for (unsigned i = 0; i < board.size(); i++)
{
for (unsigned j = 0; j < board[0].size(); j++)
{
if ('@' == board[i][j])
{
getBlacks((int)i, (int)j);
goto out;
}
}
}
out:;
printf("%d\n", blacks);
}
return 0;
}
版权声明:笔者心脏靖。景空间地址:http://blog.csdn.net/kenden23/,可能不会在未经作者同意转载。
HDU1312 Red and Black 解读的更多相关文章
- HDU1312——Red and Black(DFS)
Red and Black Problem DescriptionThere is a rectangular room, covered with square tiles. Each tile i ...
- HDU1312 Red and Black(DFS) 2016-07-24 13:49 64人阅读 评论(0) 收藏
Red and Black Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- hdu1312 Red and Black
I - Red and Black Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- hdu1312 Red and Black 简单BFS
简单BFS模版题 不多说了..... 直接晒代码哦.... #include<cstdlib> #include<iostream> #include<cstdio> ...
- HDU1312 Red and Black(dfs+连通性问题)
这有一间铺满方形瓷砖的长方形客房. 每块瓷砖的颜色是红色或者黑色. 一个人站在一块黑色瓷砖上, 他可以从这块瓷砖移动到相邻(即,上下左右)的四块瓷砖中的一块. 但是他只能移动到黑色瓷砖上,而不能移动到 ...
- Web前端温故知新-CSS基础
一.CSS定义与编写CSS 1.1 CSS的定义 全名:Cascading Style Sheets -> 层叠样式表 定义:CSS成为层叠样式表,它主要用于设置HTML页面中的文本内容(字体. ...
- PHP探针
来自LNMP.org 探针p.php 代码: <?php error_reporting(0); //抑制所有错误信息 @header("content-Type: text/html ...
- LNAMP 中的PHP探针
<?php /* ----------------本探针基于YaHei.net探针------------------- */ error_reporting(0); //抑制所有错误信息 @h ...
- HDU1312 / POJ1979 / ZOJ2165 Red and Black(红与黑) 解题报告
题目链接:pid=1312" target="_blank">HDU1312 / POJ1979 / ZOJ2165 Red and Black(红与黑) Red ...
随机推荐
- 动态接口服务 webservice
private void GetDll() { WebClient client = new WebClient(); string url = "http://xxxx/services/ ...
- iOS 多线程开发之OperationQueue(二)NSOperation VS GCD
原创Blog.转载请注明出处 blog.csdn.net/hello_hwc 欢迎关注我的iOS SDK具体解释专栏 http://blog.csdn.net/column/details/huang ...
- PHP类中的七种语法说明
类中的七种语法说明 -属性 -静态属性 -方法 -静态方法 -类常量 -构造函数 -析构函数 <?php class Student { // 类里的属性.方法和函数的訪问权限有 (函数和方法是 ...
- Unable to start MySQL service. Another MySQL daemon is already running with the same UNIX socket
Unable to start MySQL service. Another MySQL daemon is already running with the same UNIX socket 特征 ...
- JDK8在Java转让Javascript脚本引擎动态地定义和运行代码
import java.lang.*; import java.util.Arrays; import java.util.List; import javax.script.Invocable; i ...
- ftp桥接到http服务
先说一下我的需求:我的linodeserver近期ftp和sftp连不上了,port被封了.仅仅有http能够訪问,我没有办法上传文件了.由于我寻常都用beyond compare上传文件,非常方便. ...
- 树形dp专辑
hdu 2196 http://acm.hdu.edu.cn/showproblem.php?pid=2196 input 5//5个结点 1 1//表示结点2到结点1有一条权值为1的边 2 1//表 ...
- Blink: Chromium的新渲染引擎
编自http://www.chromium.org/blink 关于blink Google Chrome/Chromium 从创始至今一直使用 WebKit(WebCore) 作为 HTML/CSS ...
- atitit.标准时间格式 相互转换 秒数 最佳实践
atitit.标准时间格式 相互转换 秒数 最佳实践 例如00:01:19 转换为秒数 79,,and互相转换 一个思路是使用div 60 mod...只是麻烦的... 更好的方法是使用stamp ...
- 重新想象 Windows 8 Store Apps (32) - 加密解密: 非对称算法, 数据转换的辅助类
原文:重新想象 Windows 8 Store Apps (32) - 加密解密: 非对称算法, 数据转换的辅助类 [源码下载] 重新想象 Windows 8 Store Apps (32) - 加密 ...