社区讨论
90pts,已经炸裂了,看到wa#6点样例我陷入了沉思
P1126[CERC1996] 机器人搬重物参与者 2已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @lo10mgzq
- 此快照首次捕获于
- 2023/10/22 13:15 2 年前
- 此快照最后确认于
- 2023/11/09 19:28 2 年前
思路又双叒叕堵住了
有dl指点吗qwq
CPP#include<bits/stdc++.h>
#define rint register int
#define mmt(a,b) memset(a,b,sizeof(a))
#define test(x) cout<<#x<<" = "<<x<<endl
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout)
#define endl '\n'
#define enter putchar(endl)
//#define int long long
using namespace std;
inline void read(int &x);
inline void ffout(int x);
inline void ffout(string b);
inline void ffout(int x,char b);
inline void ffout(int x,string b);
inline void print(string name,int a[],int r);
const int inf=0x3f3f3f3f,N=1e2+10,M=1e4;
int n,sx,sy,vx,vy,h,t,cnt,m,ans=inf;
int a[N][N],b[N][N],c[N][N];
char sd;
bool check;
const int p[5]={-114,-1,0,1,0},
qx[5]={-514,0,-1,0,1},
con[5][5]={
{-114514},
{-19,1,2,4,3},
{-19,2,3,1,4},
{-81,3,2,4,1},
{0,4,3,1,2}
};
struct node{
int x,y,dir,step;// 1->up 2->left 3->down 4->right
bool rtt;
}q[M];
void out()
{
for(rint j=0;j<=n;j++)
{
for(rint i=0;i<=n;i++)
ffout(c[j][i],' ');
enter;
}
}
signed main()
{
rint i,j;
cin>>n>>m;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
cin>>a[i][j];
if(a[i][j])b[i][j]=b[i][j-1]=b[i-1][j-1]=b[i-1][j]=1;
}
// for(i=1;i<=n;i++)
// {
// for(j=1;j<=m;j++)
// {
// ffout(b[i][j],' ');
// }
// enter;
// }
cin>>sx>>sy>>vx>>vy>>sd;
if(sx==vx&&sy==vy)
{
cout<<0;
return 0;
}
// test(sx);test(sy);
// test(vx);test(vy);
// cout<<endl<<sd<<endl;
h=1;t=0;
if(sd=='S')sd=3;
if(sd=='W')sd=2;
if(sd=='E')sd=4;
if(sd=='N')sd=1;
q[++t]=node({sx,sy,sd,0,0});
b[sx][sy]=1;
c[sx][sy]=q[t].step;
while(h<=t)
{
int x=q[h].x,y=q[h].y,d=q[h].dir,curs=q[h].step;
bool rt=q[h].rtt;
h++;
if(!rt)
for(j=2;j<=4;j++)
{
int l=con[d][j];
q[++t]=node({x,y,l,curs+min(abs(d-l),4-abs(d-l)),1});
}
for(rint k=1;k<=3;k++)
{
int tx=x+p[d]*k,ty=y+qx[d]*k;
if(tx<1||ty<1||tx>=n||ty>=m)break;
if(b[tx][ty])break;
b[tx][ty]=1;
q[++t]=node({tx,ty,d,curs+1,0});
c[tx][ty]=q[t].step;
if(tx==vx&&ty==vy)
check=1;
}
if(check)
{
for(i=h;i<=t;i++)
if(q[i].x==vx&&q[i].y==vy)
ans=min(ans,q[i].step);
ffout(ans);
return 0;
}
}
// out();
cout<<-1;
return 0;
}
inline void ffout(string b)
{
int len=b.size();
for(rint i=0;i<len;++i)putchar(b[i]);
}
inline void read(int &x)
{
int f=1;x=0;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
x=x*f;
}
inline void ffout(int x)
{
if(x<0){x=-x; putchar('-'); }
short sta[63],top=0;
do{ sta[top++]=x%10; x/=10; }while(x);
while(top) putchar(sta[--top]+'0');
}
inline void ffout(int x,char b)
{
if(x<0){x=-x; putchar('-'); }
short sta[63],top=0;
do{ sta[top++]=x%10; x/=10; }while(x);
while(top) putchar(sta[--top]+'0');
putchar(b);
}
inline void ffout(int x,string b)
{
if(x<0){x=-x; putchar('-'); }
short sta[63],top=0;
do{ sta[top++]=x%10; x/=10; }while(x);
while(top) putchar(sta[--top]+'0');
ffout(b);
}
inline void print(string name,int a[],int r)
{
ffout(name);
putchar(':');
for(rint i=1;i<=r;i++)
ffout(a[i],' ');
putchar(endl);
}
回复
共 4 条回复,欢迎继续交流。
正在加载回复...