没人看啊!!!求助SP2128
  • 板块题目总版
  • 楼主_Hu_Tao
  • 当前回复2
  • 已保存回复2
  • 发布时间2022/8/24 11:21
  • 上次更新2023/10/27 13:54:32
查看原帖
没人看啊!!!求助SP2128
750558
_Hu_Tao楼主2022/8/24 11:21

WA了,题目链接

#include<bits/stdc++.h>
using namespace std;
long long t,n,m,k,of,xf,osum,xsum;
char mat[1005][1005];
void work1(){
	osum=0;
	xsum=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(mat[i][j]=='o'){
				xsum=0;
				osum++;
			}
			else if(mat[i][j]=='x'){
				osum=0;
				xsum++;
			}
			if(osum>=k){
				of++;
				return ;
			}
			if(xsum>=k){
				xf++;
				return ;
			}
		}
		osum=0;
		xsum=0;
	}
}
void work2(){
	osum=0;
	xsum=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(mat[j][i]=='o'){
				xsum=0;
				osum++;
			}
			else if(mat[j][i]=='x'){
				osum=0;
				xsum++;
			}
			if(osum>=k){
				of++;
				return ;
			}
			if(xsum>=k){
				xf++;
				return ;
			}
		}
		osum=0;
		xsum=0;
	}
}
void work3(){//左扫
	osum=0;
	xsum=0;
	for(int i=0;i<n;i++){
		int j=0;
		int t=i;
		for(int l=0;l<m;l++){
			if((t<0||j>=n)){
				osum=0;
				xsum=0;
				break;
			}
			else{
				if(mat[t][j]=='o'){
					xsum=0;
					osum++;
				}
				else if(mat[t][j]=='x'){
					osum=0;
					xsum++;
				}
				if(osum>=k){
					of++;
					return ;
				}
				if(xsum>=k){
					xf++;
					return ;
				}
				t--;
				j++;
			}	
		}
		continue;	
	}
}
void work4(){//右扫
	osum=0;
	xsum=0;
	for(int i=0;i<n;i++){
		int j=n-1;
		int t=i;
		for(int l=0;l<m;l++){
			if((t<0||j>=n)){
				osum=0;
				xsum=0;
				break;
			}
			else{
				if(mat[t][j]=='o'){
					xsum=0;
					osum++;
				}
				else if(mat[t][j]=='x'){
					osum=0;
					xsum++;
				}
				if(osum>=k){
					of++;
					return ;
				}
				if(xsum>=k){
					xf++;
					return ;
				}
				t--;
				j--;
			}	
		}
		continue;	
	}
}
int main(){
	cin>>t;
	for(int i=1;i<=t;i++){
		memset(mat,'.',sizeof(mat));
		cin>>n>>m>>k;
		for(int i=0;i<m;i++){
			for(int j=0;j<n;j++){
				cin>>mat[i][j];
			}
		}
		work1();
		work2();
		work3();
		work4();
	}
	printf("%d:%d",xf,of);
}
2022/8/24 11:21
加载中...