各位大佬康一康,这有什么问题?
#include<bits/stdc++.h>
using namespace std;
long long n,m;
long long a[100005][100005];
long long sx,sy;
long long ans=0;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
char b;
cin>>b;
if(b=='S') a[i][j]=1;
if(b=='K') a[i][j]=2;
if(b=='.') a[i][j]=3;
if(a[i][j]==1){
sx=i;
sy=j;
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++){
if(a[i][j]==2){
++ans;
long long tx,ty,ttx,tty,t,xx,yy,txt,tyt;
xx=sx;
yy=sy;
ttx=i-sx;
tty=j-sy;
t=__gcd(abs(ttx),abs(tty));
txt=ttx/t;
tyt=tty/t;
tx=txt;
ty=tyt;
xx+=tx;
yy+=ty;
for(;xx>=1 && xx<=n && yy>=1 && yy<=m;){
a[xx][yy]=3;
xx+=tx;
yy+=ty;
}
}
}
}
cout<<ans;
return 0;
}