【急】求解
  • 板块灌水区
  • 楼主小坦克
  • 当前回复15
  • 已保存回复15
  • 发布时间2020/11/2 23:19
  • 上次更新2023/11/5 09:09:37
查看原帖
【急】求解
255199
小坦克楼主2020/11/2 23:19

各位大佬康一康,这有什么问题?

#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;
}
2020/11/2 23:19
加载中...