复仇者_必胜啊的模拟方法修改
2024-06-18 21:53:37
发布于:广东
34阅读
0回复
0点赞
他没判断i+1和j+1有没有超出界限
然后我帮忙省了一大堆代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int a[n][m];
memset(a,0,sizeof(a));
int cnt=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(a[i][j]==0 and a[i][j+1]==0 and j+1!=m)
{
cnt++;
a[i][j]=1;
a[i][j+1]=1;
}
else if(a[i][j]==0 and a[i+1][j]==0 and i+1!=n)
{
cnt++;
a[i][j]=1;
a[i+1][j]=1;
}
}
}
cout<<cnt;
}
这里空空如也
有帮助,赞一个