P1913 L国的战斗之伞兵

题目链接

P1913 L国的战斗之伞兵

思路

从无风点倒着dfs,本来是道大水题,结果输入的时候第二层循环打错了!手残打成i++

代码

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<string>
#include<cstring>
using namespace std;
inline int read() {
	char c = getchar();
	int x = 0, f = 1;
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
char a[1001][1001];
int n,m;
bool is_ok[1001][1001];
void dfs(int x,int y) {
	is_ok[x][y]=true;
	if(a[x+1][y]=='u'&&x+1<=n) dfs(x+1,y);
	if(a[x-1][y]=='d'&&x-1>=1) dfs(x-1,y);
	if(a[x][y+1]=='l'&&y+1<=m) dfs(x,y+1);
	if(a[x][y-1]=='r'&&y-1>=1) dfs(x,y-1);
}
signed main() {
	cin>>n>>m;
	for(int i=1; i<=n; ++i) {
		for(int j=1; j<=m; ++j) {
			cin>>a[i][j];
		}
	}
	/*“u”表示风向北吹;“d”表示风向南吹;“l”表示风向西吹;
	“r”表示风向东吹;“o”表示无风。(上北下南,左西右东)*/
	for(int i=1; i<=n; ++i) {
		for(int j=1; j<=m; ++j) {
			if(a[i][j]=='o') {
				dfs(i,j);
			}
		}
	}
	int ans=0;
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=m;++j)
		{
			if(is_ok[i][j])
			{
				ans++;
			}
		}
	}
	cout<<ans;
	return 0;
}
posted @ 2019-05-23 11:30  pyyyyyy  阅读(190)  评论(1编辑  收藏  举报