Gym102156J The Good, the Bad and the Ugly
Link 显然只要到了原点,我们就能轻松地进行判断。 首先我们观察到,在第一次到达原点之前,我们不可能越过而不经过原点。 考虑倍增,先往右跳 \(1\) 步,然后往左跳 \(c\) 步,再往右跳 \(c^2\) 步, \(\cdots\) ,第 \(i\) 轮跳 \(c^{i-1}\) 步。 取 \(c=3.5\) ,那么我们就可以在 \(25m\) 次指令内到达原点。 #include<cstdio> int read(){int x;scanf("%d",&x);return x;} int query(int f){return printf("%c",f?'+':'-'),fflush(stdout),read();} int main() { for(int s=1,f=1,is0=0;!is0;f^=1,s*=3.5) for(int i=1;!is0&&i<=s;++i) is0=query(f); return puts(query(1)||query(0)? "! ugly":query(0)? "! good":"! bad"),0; } 来源: https://www.cnblogs.com/cjoierShiina-Mashiro/p/12655473.html