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

真是神题

[杂题 交互] Codeforces Gym 101190 NEERC 16 I. Indiana Jones and the Uniform Cave_第1张图片
[杂题 交互] Codeforces Gym 101190 NEERC 16 I. Indiana Jones and the Uniform Cave_第2张图片
[杂题 交互] Codeforces Gym 101190 NEERC 16 I. Indiana Jones and the Uniform Cave_第3张图片

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

#include
#include
#include
#include
#include
#include
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 (tmpelse{
      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 (depelse
      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 (depreturn 0;
}

你可能感兴趣的:(杂题,交互题&提交答案题)