liuhanbin313 @ 2024-10-28 17:48:51
#include<bits/stdc++.h>
using namespace std;
int main()
{
freopen("explore3.in","r",stdin);
freopen("explore3.out","w",stdout);
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
int a,b,c,d,e,f,sum=0;
cin>>a>>b>>c>>d>>e>>f;
char map[a+1][b+1];
int g[a+1][b+1]={0},h[a+1][b+1]={0};
for(int j=1;j<=a;j++)
{
for(int k=1;k<=b;k++)
{
cin>>map[j][k];
if(map[j][k]=='.')
{
g[j][k]=1;
}
}
}
int rx,ry,r;
rx=d;
ry=e;
r=f;
for(int l=1;l<=c;l++)
{
int rrx=rx,rry=ry;
if(r==0)
{
ry+=1;
}
if(r==1)
{
rx+=1;
}
if(r==2)
{
ry-=1;
}
if(r==3)
{
rx-=1;
}
if(rx<1 or ry<1 or rx>a or ry>b or g[rx][ry]==0)
{
rx=rrx;
ry=rry;
r=(r+1)%4;
continue;
}
else
{
if(h[rx][ry]==0)
{
h[rx][ry]=1;
sum++;
}
}
}
cout<<sum+1<<endl;
}
}
by liuhanbin313 @ 2024-10-28 17:53:15
不要管freopen
by Eason1010 @ 2024-10-28 17:55:57
是RE/MLE吗,如果是的话我觉得应该是main函数内定义
by liuhanbin313 @ 2024-10-28 17:58:42
wa
by xianjunyong @ 2024-10-28 18:35:46
@liuhanbin313 走过的路径可能经过机器人起始位置,先把h[d][e]标记,sum初值为1,最终输出sum,就可以过了
by cpp_xhq @ 2024-10-28 18:41:41
@liuhanbin313
本人以将代码修改
#include<bits/stdc++.h>
using namespace std;
char mp[1005][1005];
int g[1005][1005]={0},h[1005][1005]={0};
int main()
{
// freopen("explore3.in","r",stdin);
// freopen("explore3.out","w",stdout);
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
memset(h,0,sizeof(h));
memset(g,0,sizeof(g));
int a,b,c,d,e,f,sum=1;
cin>>a>>b>>c>>d>>e>>f;
for(int j=1;j<=a;j++)
{
for(int k=1;k<=b;k++)
{
cin>>mp[j][k];
if(mp[j][k]=='.')
{
g[j][k]=1;
}
}
}
int rx,ry,r;
rx=d;
ry=e;
r=f;
h[rx][ry]=1;
for(int l=1;l<=c;l++)
{
int rrx=rx,rry=ry;
if(r==0)
{
ry+=1;
}
if(r==1)
{
rx+=1;
}
if(r==2)
{
ry-=1;
}
if(r==3)
{
rx-=1;
}
if(rx<1||ry<1||rx>a||ry>b||g[rx][ry]==0)
{
rx=rrx;
ry=rry;
r=(r+1)%4;
continue;
}
else
{
if(h[rx][ry]==0)
{
h[rx][ry]=1;
sum++;
}
}
}
cout<<sum<<endl;
}
}
这个代码是AC的,我帮你整理了数组!!
原来50的原因是:没有将
h[rx][ry]=1;
开始的点也需要加入
(本人在CSP中也遇到了,用大样例检查出来了。)
本人提醒,很重要!!!!
freopen("explore3.in","r",stdin);
freopen("explore3.out","w",stdout);
这个是错的
freopen("explore.in","r",stdin);
freopen("explore.out","w",stdout);
一定要注意!!!!不然爆0!!!
by liuhanbin313 @ 2024-10-28 19:28:15
考场上大数据过了(6)