警示后人2
查看原帖
警示后人2
552688
clx201022楼主2023/7/12 09:27

如果你使用一个结构体栈来存数据的话, 不要像这样直接套:

struct node{int x,y;};
stack<node>s;
//一堆代码
  for(int i2=0;i2<4;i2++)
  {
    int x2=s.top().x+st_x[i2],y2=s.top().y/*这里不要打成x!别问我怎么知道的!*/+st_y[i2];
    if(x2<1||y2<1||x2>m||y2>n||stop[y2][x2])
      continue;
    stop[y2][x2]=i+2;
    s.push(node{x2,y2});
  }
  s.pop();

而应该像这样:

struct node{int x,y;};
stack<node>s;
//一堆代码
node zzz=s.top();
s.pop();
  for(int i2=0;i2<4;i2++)
  {
    int x2=zzz.x+st_x[i2],y2=zzz.y/*这里不要打成x!别问我怎么知道的!*/+st_y[i2];
    if(x2<1||y2<1||x2>m||y2>n||stop[y2][x2])
      continue;
    stop[y2][x2]=i+2;
    s.push(node{x2,y2});
  }

不要问我怎么知道的!

2023/7/12 09:27
加载中...