POJ 1979 Red and Black(水题,递归)
一开始理解错题意了,以为是走过的砖不能再重复走,最多能走多少个黑砖,结果写的递归陷入死循环。。。
后来才明白原来可以重复走,问可以到达的磁砖数。
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <algorithm> using namespace std;
int w,h,num,ans;
int f[][];//存储地图的信息,为0代表是黑砖,为1代表红砖,2代表已走过该砖 void search(int row,int col){
if(row<||row>h||col<||col>w){
return;
}
if(f[row][col]==||f[row][col]==)
return;
num++;
f[row][col]=; search(row,col-);
search(row,col+);
search(row-,col);
search(row+,col); }
int main()
{
int px,py;
char str[];
while(scanf("%d%d",&w,&h)!=EOF){
if(w== && h==)
break;
memset(f,,sizeof(f));
num=;
ans=;
for(int i=;i<=h;i++){
scanf("%s",str);
//一开始j从1开始了,囧。。。
for(int j=;j<w;j++){
if(str[j]=='#')
f[i][j+]=;
else if(str[j]=='@'){
//f[i][j]=2;
px=i;
py=j+;
}
}
}
search(px,py);
printf("%d\n",num);
}
return ;
}
POJ 1979 Red and Black(水题,递归)的更多相关文章
- POJ 1979 Red and Black (红与黑)
POJ 1979 Red and Black (红与黑) Time Limit: 1000MS Memory Limit: 30000K Description 题目描述 There is a ...
- poj 3080 Blue Jeans(水题 暴搜)
题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...
- POJ 3984 - 迷宫问题 - [BFS水题]
题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...
- poj 1007:DNA Sorting(水题,字符串逆序数排序)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 80832 Accepted: 32533 Des ...
- poj 1004:Financial Management(水题,求平均数)
Financial Management Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 126087 Accepted: ...
- POJ 3176 Cow Bowling (水题DP)
题意:给定一个金字塔,第 i 行有 i 个数,从最上面走下来,只能相邻的层数,问你最大的和. 析:真是水题,学过DP的都会,就不说了. 代码如下: #include <cstdio> #i ...
- poj 1658 Eva's Problem(水题)
一.Description Eva的家庭作业里有很多数列填空练习.填空练习的要求是:已知数列的前四项,填出第五项.因为已经知道这些数列只可能是等差或等比数列,她决定写一个程序来完成这些练习. Inpu ...
- poj 1979 Red and Black(dfs水题)
Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...
- OpenJudge/Poj 1979 Red and Black / OpenJudge 2816 红与黑
1.链接地址: http://bailian.openjudge.cn/practice/1979 http://poj.org/problem?id=1979 2.题目: 总时间限制: 1000ms ...
随机推荐
- Fragstats景观分析研究
QQ 交流群: Fragstats景观分析 加群链接:http://url.cn/N4wZ3N
- Tables for condition techniques
T682i -- Access sequence and the tables T685 -- Condition types and Access sequences T683s -- ...
- window store app 附件读取
public static async Task<bool> DisplayApplicationPicker(string folderName, string fileName) { ...
- PHP CodeIgniter(CI)去掉 index.php
去掉CodeIgniter(CI)默认url中的index.php的步骤: 1.打开apache的配置文件,conf/httpd.conf : LoadModule rewrite_module mo ...
- highchars
var drawChart = function(sourceUrl) { $.ajax({ "type" : "post", "url" ...
- 使用CSS画一个三角形
<div style="width:0px;height:0px;border-width:40px;border-style:solid;border-color:transpare ...
- Jquery LigerUI框架学习(一)
ligerUI框架是一个很丰富的后台框架模板,具有简洁大方的后台样式框架,还有很多灵活的控件,方便开发人员使用: 把昨天学习的成功拿出来供大家学习学习: 首先我们要去ligerUI官网下载Jquery ...
- 连续子数组的最大和/1007. Maximum Subsequence Sum (25)
题目描述 HZ偶尔会拿些专业问题来忽悠那些非计算机专业的同学.今天测试组开完会后,他又发话了:在古老的一维模式识别中,常常需要计算连续子向量的最大和,当向量全为正数的时候,问题很好解决.但是,如果向量 ...
- IO流的异常处理
在IO流的异常处理时应该注意以下几点: 1.在外边建立引用,在Try内进行初始化(FileWriter fw = null;) 2.文件的路径使用必须是双斜杠,转义(fw = new FileWrit ...
- matlab实现共轭梯度法、多元牛顿法、broyden方法
共轭梯度法: function [ x, r, k ] = CorGrant( x0, A, b ) x = x0; r = b - A * x0; d = r; X = ones(length(x) ...