poj 2017 Red and Black
来源:互联网 发布:上瘾网络剧新闻发布会 编辑:程序博客网 时间:2024/06/05 01:18
Description
@是人的位置 点是可以踩的 #不可以踩,人只能,上下左右移动,求出人可以踩到的点的数量。
Output
6 9....#......#..............................#@...#.#..#.11 9.#..........#.#######..#.#.....#..#.#.###.#..#.#..@#.#..#.#####.#..#.......#..#########............11 6..#..#..#....#..#..#....#..#..###..#..#..#@...#..#..#....#..#..#..7 7..#.#....#.#..###.###...@...###.###..#.#....#.#..0 0
Sample Output
4559613
analysis:很明显的递归题,首先找出@的坐标,从@出发向四个方向,然后 相同的步骤
递归停止条件:1.超出边界。2遇到#。3 遇到已经分析过的。(另建一个数组来标记是否分析过)
#define LOCAL#include <iostream>using namespace std;char shuz[20][20];int panduan[20][20];int sum;void jis(int qx,int qy,int x,int y);int main(int argc, char *argv[]){ #ifdef LOCAL freopen("2.txt","r",stdin); #endifint x,y;while(cin>>x>>y,x!=0||y!=0){sum=0;memset(panduan,0,sizeof(panduan)); //输入图形 for(int j=0;j<y;++j) for(int i=0;i<x;++i) cin>>shuz[j][i]; //找到@的位置 int qx,qy; for(int j=0;j<y;++j) for(int i=0;i<x;++i) if(shuz[j][i]=='@'){qx=i;qy=j;} jis(qx,qy,x,y); cout<<sum<<endl;}return 0;}void jis(int qx,int qy,int x,int y) //qx,qy为当前坐标,x,y是边界{ //三个停止条件 if(qy>=y||qy<0||qx>=x||qx<0)return; if(shuz[qy][qx]=='#')return;//遇到 #或者超出界面停止 if(panduan[qy][qx]==1)return;else {++sum;panduan[qy][qx]=1;}// sum+1 并标记为分析过的 //递归调用 jis(qx,qy-1,x,y); jis(qx-1,qy,x,y); jis(1+qx,qy,x,y); jis(qx,1+qy,x,y);}
- poj 2017 Red and Black
- poj Red and Black
- Red and Black POJ
- Red and Black POJ
- Red and Black POJ
- POJ 1979 Red and Black
- poj 1979 Red and Black
- POJ 1979 - Red and Black
- POJ-1979-Red and Black
- poj 1979 red and black
- poj 1979 Red and Black
- poj 1979 Red and Black
- POJ:1979 Red and Black
- POJ 1979 - Red and Black
- POJ 1979 Red and Black
- poj 3866: Red and Black
- POJ 1979 Red and Black
- POJ 1979 Red and Black
- onInterceptTouchEvent和onTouchEvent调用时序
- <action name="userAction_save" class="app.converter.UserAction" method="save">
- USACO Packing Rectangles
- 三维显示软件制作---GUI部分
- SendTo命令的运用
- poj 2017 Red and Black
- Linux逻辑卷管理(LVM)操作笔记
- Eclipse上安装ivy插件
- LUA string.format的小改进
- mysql存储过程一次连接多次调用失败的问题解决
- 毕设经验
- 【Linux入门系列】wget 使用探索
- 2013年,,噢,,
- SCOI2006——动态最值(线段树)