说实话,您的代码有点乱
by momentous @ 2019-06-03 08:54:47
@[leprechaun_kdl](/space/show?uid=156924) https://www.luogu.org/recordnew/show/19589288
by momentous @ 2019-06-03 08:58:01
@[ErkkiErkko](/space/show?uid=52468)
@[lyslys](/space/show?uid=42714)
@[02Irving11](/space/show?uid=104887)
@[lzx1999](/space/show?uid=132994)
--------leprechaun_kdl--------
非常抱歉,这样的一道题还需要麻烦大家。
我已经看过了你们的建议,但是这段代码的错误并没有被指出。这里我强调一下让大家以后注意。
~~今天上午生物课因为无聊在发呆时~~突然想到了**错误的根本原因:::**
ios::sync_with_stdio(0),cin.tie(0);
大家都知道这句话可以增快cin,cout的速度。
但此时需要**特别注意**:
ios::sync_with_stdio(0),使用本行代码时cin与scanf不能混用!!否则会有奇怪的错误。
cin.tie(0),使cin与cout的绑定接触,所以cout可以正常使用。
```cpp
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ri register ll
ll m,n,tot;
ll a[105][105];
bool vis[105][105];
ll wayx[]={1,-1,0,0};
ll wayy[]={0,0,1,-1};
void dfs(ll x,ll y)
{
vis[x][y]=1;
// cout<<x<<" "<<y<<" -- "<<tot<<'\n';
for(ri i=0;i<4;i++)
{
ri xx=x+wayx[i],yy=y+wayy[i];
if(xx<1 || xx>m || yy<1 || yy>n)continue;
if(vis[xx][yy] || !a[xx][yy])continue;
dfs(xx,yy);
}
return;
}
signed main()
{
//ios::sync_with_stdio(0),cin.tie(0);
//cin>>m>>n;
scanf("%lld%lld",&m,&n);
for(ri i=1;i<=m;i++)
{
for(ri j=1;j<=n;j++)
{
scanf("%1lld",&a[i][j]);
}
}
for(ri i=1;i<=m;i++)
{
for(ri j=1;j<=n;j++)
{
if(vis[i][j] || !a[i][j])continue;
dfs(i,j);
tot++;
}
}
cout<<tot<<'\n';
return 0;
}
//
```
by leprechaun_kdl @ 2019-06-03 13:29:18
我并没有指出你的错误,只是我学了一年半OI并不知道可以像你这样用```%1d```输入单个字符(数字)的。
我感觉我C语法白学了。
长姿势了。。
by ErkkiErkko @ 2019-06-03 13:38:59
涨姿势了(字打错了233
by ErkkiErkko @ 2019-06-03 13:39:31
%1d的读入方式还是我右边的大佬
@[wangzhifang](/space/show?uid=35347)
教我的
原因:用程序碾压做数独的人
by momentous @ 2019-06-03 15:33:33
@[leprechaun_kdl](/space/show?uid=156924) 用哪个是c和c++的读入输出不能同时用
by lzx1999 @ 2019-06-03 19:14:54
@[leprechaun_kdl](/space/show?uid=156924) 偷偷告诉你关闭同步的cin,cout比scanf和printf快
by lzx1999 @ 2019-06-03 19:16:12
@[lzx1999](/space/show?uid=132994)
ios::sync_with_stdio(false)
by leprechaun_kdl @ 2019-06-03 23:12:44