F - Red and Black

有一个长方形的房间,覆盖了正方形的磁砖。每块磁砖的颜色,要么是红色,要么是黑色。一名男子站在一块黑色的磁砖上。他可以从一块磁砖移至相邻四块磁砖中的某一块。但是,他不允许在红色磁砖上移动,他只允许在黑色磁砖上移动。

编写一个程序,使得他允许重复上述的移动,判断他所能到达的黑色磁砖的数量。

输入

输入由多个数据集组成。数据集的起始行包含了两个正整数 W 和 H;W 和 H 分别是 x- 和 y- 方向的磁砖数量。W 和 H 不超过 20 。

在数据集中,还有 H 行,每行包含了 W 个字符。每个字符按如下方式表示一块磁砖的颜色。

'.' - 一块黑色的磁砖
'#' - 一块红色的磁砖
'@' - 一名男子,站在一块黑色磁砖上 (在一个数据集中,恰好出现一次)

以包含两个 0 的一行,表示输入结束。

输出

对于每个数据集,程序应当输出一行,包含他从初始磁砖所能抵达的磁砖数量 (包括初始磁砖自身)。

示例输入

6 9
....#.
.....#
......
......
......
......
......
#@...#
.#..#.
11 9
.#.........
.#.#######.
.#.#.....#.
.#.#.###.#.
.#.#..@#.#.
.#.#####.#.
.#.......#.
.#########.
...........
11 6
..#..#..#..
..#..#..#..
..#..#..###
..#..#..#@.
..#..#..#..
..#..#..#..
7 7
..#.#..
..#.#..
###.###
...@...
###.###
..#.#..
..#.#..
0 0

示例输出

45
59
6
13
#include<iostream>
#include<string.h>
using namespace std;
int hang,lie;
char a[30][30];
int pan[30][30]={0};
int fang[4][2]={{1,0},{-1,0},{0,1},{0,-1}};//方位数组 
int ans;
void dfs(int w,int y){//此次dfs没有判断条件,如果 到头了没有没能继续判断的位置了结束循环 ; 
	
	int ww,yy;
	for(int i=0;i<4;i++){
		ww=w+fang[i][0];//为什么要在引一格书最为方向,这里是做加,如果这个方向不对要重置w但如果只用w=w+..的话w的数值已变; 
		yy=y+fang[i][1];//所以要重设置; 
		if(ww<0||ww>=hang||yy<0||yy>=lie||pan[ww][yy]==1||a[ww][yy]=='#'){
			continue;
		} 
		ans++;
		pan[ww][yy]=1;
		dfs(ww,yy);
	}
}
int main()
{

	int qi1,qi2;
	while(scanf("%d %d",&lie,&hang)!=EOF){
		if(hang==0&&lie==0){
			break;
		}
		ans=1;
		for(int i=0;i<hang;i++){
			for(int j=0;j<lie;j++){
				cin >> a[i][j];
				if(a[i][j]=='@'){
					qi1=i,qi2=j;
				}
			}
		}
		pan[qi1][qi2]=1;//标记初始位置 
		dfs(qi1,qi2);
		cout << ans <<endl;
		memset(pan,0,sizeof(pan));//重置pan数组。 
	}
	return 0;
 } 

 

gmx xpm2ps -f dssp.xpm -o secondary-structure.eps -title none -di 1.m2p -rainbow red可以将xom文件转化成eps,请修改以下代码,使其只显示只显示alpha-helix与beta-sheet,使alpha-helix用蓝色表示,beta-sheet用黄色表示。; Command line options of xpm2ps override the parameters in this file black&white = no ; Obsolete titlefont = Times-Roman ; A PostScript Font titlefontsize = 20 ; Font size (pt) legend = yes ; Show the legend legendfont = Times-Roman ; A PostScript Font legendlabel = ; Used when there is none in the .xpm legend2label = ; Used when merging two xpm’s legendfontsize = 14 ; Font size (pt) xbox = 2.0 ; x-size of a matrix element ybox = 2.0 ; y-size of a matrix element matrixspacing = 20.0 ; Space between 2 matrices xoffset = 0.0 ; Between matrix and bounding box yoffset = 0.0 ; Between matrix and bounding box x-major = 20 ; Major ticks on x axis every … frames x-minor = 5 ; Id. Minor ticks x-firstmajor = 0 ; First frame for major tick x-majorat0 = no ; Major tick at first frame x-majorticklen = 8.0 ; x-majorticklength x-minorticklen = 4.0 ; x-minorticklength x-label = ; Used when there is none in the .xpm x-fontsize = 16 ; Font size (pt) x-font = Times-Roman ; A PostScript Font x-tickfontsize = 10 ; Font size (pt) x-tickfont = Helvetica ; A PostScript Font y-major = 20 y-minor = 5 y-firstmajor = 0 y-majorat0 = no y-majorticklen = 8.0 y-minorticklen = 4.0 y-label = y-fontsize = 16 y-font = Times-Roman y-tickfontsize = 10 y-tickfont = Helvetica
最新发布
06-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值