这很奇怪诶......
查看原帖
这很奇怪诶......
407417
HerikoDeltana楼主2021/4/9 19:42

关于这份代码,在本地跑样例答案是44

然后提交评测#1就挂了,然而#1是样例

于是我把代码复制到洛谷在线IDE

然后它给我输出33

我人傻了

/*
4 10
0234500067
1034560500
2045600671
0000000089
*/
#include <bits/stdc++.h>
#define Heriko return
#define Deltana 0
using namespace std;
inline void fr(int &x)
{
	int f=1;char c=getchar();
	x=0;
	while(c<'0'||c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	x*=f;
}
int n,m,ans;char a[115];bool v[115][115],vis[115][115];
int X[5] = { 0,-1,0,1,0 },Y[5] = { 0,0,-1,0,1 };
inline void search(int t1,int t2)
{
	v[t1][t2]=false;vis[t1][t2]=true;
	for(int i=1;i<=4;i++)
	{
		int x=t1+X[i],y=t2+Y[i];
		if(x>0 && x<=n && y>0 && y<=m && v[x][y] && !vis[x][y]) search(x,y);
	}
	Heriko;
}
signed main()
{
	fr(n),fr(m);
//	memset(v,false,sizeof(v));
//	memset(vis,true,sizeof(vis));
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			v[i][j]=false;
			vis[i][j]=false;
		}
	}
	for(int i=1;i<=n;i++)
	{
		gets(a);
		for(int j=1;j<=m;j++)
		{
			int temp=a[j-1];
			if(temp!='0') v[i][j]=true;
		}
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(!vis[i][j] && v[i][j])
			{
				ans++;search(i,j);
			}
	printf("%d\n",ans);
	Heriko Deltana;
}
2021/4/9 19:42
加载中...