CF436B Om Nom and Spiders

传送门

题目思路

蜘蛛的移动方向只有四个(有用的只有三个,方向向下的蜘蛛不会对答案产生任何贡献),所以做法是枚举每一个位置,倒推出原来蜘蛛可能存在的位置,如果确实有则改位置答案数加一。

对向上走的蜘蛛有另一种方法处理,题解区有人讲解,这里不赘述。

AC Code

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2005;
int ans,n,m,k,a[N][N];
char c[N][N]; 
signed main(){
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>c[i][j];
	for(int j=1;j<=m;j++){
		for(int i=2;i<=n;i++){
			int t=i-1;//理解为 当前时间 
			if(i+t<=n&&c[i+t][j]=='U')	a[i][j]++;
			if(j+t<=m&&c[i][j+t]=='L')	a[i][j]++;
			if(j-t>=1&&c[i][j-t]=='R')	a[i][j]++; 
		}
		ans=0;
		for(int i=1;i<=n;i++)	ans+=a[i][j];
		cout<<ans<<" ";
	}
	return 0;
}
posted @ 2026-03-03 17:05  深申  阅读(1)  评论(0)    收藏  举报