[杂题 交互] Codeforces Gym 101190 NEERC 16 I. Indiana Jones and the Uniform Cave

真是神题

这里写图片描述
这里写图片描述
这里写图片描述

其实递归的写是不难写的
我在昏昏欲睡的时候参考了别人的代码 写了手工栈非递归的 意识模糊

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<string>
#include<iostream>
using namespace std;

string ret;
int tot;
inline void P(int x,int y,int z){
  ++tot;
  printf("%d %s %d\n",x,!y?"left":"right",z);fflush(stdout);
  cin>>ret; if (ret=="treasure") exit(0);
}

int m;

stack<int> p,pos,low,fa;

#define oo 1<<30
#define opt (ret=="right")

int main(){
  freopen("t.in","r",stdin);
  freopen("t.out","w",stdout);
  cin>>m;
  p.push(0); pos.push(-1); low.push(oo); fa.push(-1);
  cin>>ret;
  while (1){
    if (p.top()==m){
      int cnt=0;
      P(pos.top()%m,0,pos.top()%m),cnt++;
      while (ret!="right") P(0,0,0),cnt++;
      do P(0,1,0),cnt++; while (ret!="left");
      while (--cnt) P(0,opt,0);

      int tmp=low.top();
      p.pop(); pos.pop(); low.pop();
      if (tmp<low.top())
    pos.top()=fa.top(),low.top()=tmp;
      fa.pop();
    }else{
      p.top()++; P(1,1,1);
      string _ret=ret;
      if (_ret=="center"){
    fa.push(p.top()); p.push(0); pos.push(-1); low.push(oo);
      }else if (_ret=="right"){
    int cnt=0,tmp;
    P(0,0,0);
    while (ret!="left") P(0,1,0),cnt++;
    tmp=cnt; while (tmp--) P(0,1,0);

    if (cnt){
      int dep=(int)p.size()-cnt;
      if (dep<low.top())
        pos.top()=p.top(),low.top()=dep;
    }else
      P(0,1,0);
      }else{
    int cnt=0,dep=(int)p.size()+1;
    do P(0,opt,0),cnt++; while (ret!="right");
    do P(0,opt,0),cnt++,dep--; while (ret!="left");
    while (--cnt) P(0,opt,0);

    if (dep<low.top())
      pos.top()=p.top(),low.top()=dep;
      }
    }
  }
  return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值