求助!这个程序怎么既有算错的,又会超时
查看原帖
求助!这个程序怎么既有算错的,又会超时
727398
123456789qaz楼主2022/6/14 18:14

本蒟蒻自己写的程序,总想不出哪里有什么问题,做了一切能想到的优化,但总是有错,

求助大佬~

#include<iostream>
#include<cstring>
#include<math.h>
using namespace std;
int w,h;
short int a[185][185];
int s[185][185];
int main(){
	int w,h;
	string in1;
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		cin>>in1;
		for(int j=1;j<=w;j++){
			a[i][j]=in1[j-1]-'0';
		}
	}
	bool isx;
	int x;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(a[i][j]==1){
				s[i][j]=0;
			}
			else{
				isx=true;
				x=1;
				while(isx){
					if(a[i-x][j]==1 || a[i+x][j]==1 || a[i][j-x]==1 || a[i][j+x]==1 || a[i-x+1][j-x+1]==1 || a[i-x+1][j+x-1]==1 || a[i+x-1][j-x+1]==1 || a[i+x-1][j+x-1]==1){
						isx=false;
						s[i][j]=x;
						break;
					}
					x++;
				}
			}
		}
		
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cout<<s[i][j]<<' ';
		}
		cout<<endl;
	}
	return 0;
} 
2022/6/14 18:14
加载中...