又是一个
  • 板块灌水区
  • 楼主StarryWander
  • 当前回复4
  • 已保存回复4
  • 发布时间2020/11/25 22:28
  • 上次更新2023/11/5 07:20:12
查看原帖
又是一个
247220
StarryWander楼主2020/11/25 22:28

跪求大佬回复orz

(我发的贴子好久没人回复了

又是一个样例过了,但WA的题目,但又找不出问题...

题目

代码:

#include<bits/stdc++.h>
using namespace std;
struct node{
	int x,y,l,r;
};
node off[4]={{0,1},{0,-1},{1,0},{-1,0}};
int n,m,r,c,k1,k2,sum;
char a[2001][2001];
int main(){
	cin>>n>>m>>r>>c>>k1>>k2;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	queue<node>q;
	sum=1;
	a[r][c]='+';
	q.push((node){r,c,0,0});
	while(!q.empty()){
		for(int i=0;i<4;i++){
			node x=q.front();
			x.x=q.front().x+off[i].x;
			x.y=q.front().y+off[i].y;
			if(i==0) x.r++;
			else if(i==1) x.l++;
			if(x.x>=1&&x.x<=n&&x.y>=1&&x.y<=m&&a[x.x][x.y]=='.'&&x.l<=k1&&x.r<=k2){
				q.push((node){x.x,x.y,x.l,x.r});
				a[x.x][x.y]='+';
				sum++;
			}
		}
		q.pop();
	}
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=m;j++){
//			cout<<a[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	cout<<sum;
	return 0;
}

2020/11/25 22:28
加载中...