Fuck the world!
题意:
一行n个盒子,里面装着一个什么鬼,你不知道它装在哪,每次可以伸手探查一个盒子,如果什么鬼在那个盒子里,就结束,如果不在,什么鬼会往他左边或者右边移动一个盒子,要求对应一个n输出一种策略,一定能找到什么鬼。
策略见代码,实现上注意2要特判。原因如下:在从2向右走的时候可以验证,会找到所有什么鬼初始在偶数位置的情况,然后在n-1再等一次,往回走到2,就会遍历所有什么鬼在奇数位置的情况。
Input
The only input line contains the number
n of pedestals in the fourth hall of the Temple of Five Polyhedra (2 ≤
n ≤ 100).
Output
In the first line output the number
m (
m ≤ 1000) of touches necessary to find the Dodecahedron. In the second line output
m integers separated with a space; these should be the numbers of pedestals in the order in which the dodecahedra mounted on them should be touched.
The algorithm must achieve the goal for any initial position of the artifact and for any of its admissible transitions. It is guaranteed that there exists at least one such algorithm in which at most one thousand touches are made.
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n;
int main(){
while(scanf("%d",&n)!=EOF){
if(n==2){
printf("2\n2 2\n");
continue;
}
printf("%d\n",2*(n-2));
printf("2");
for(int i=3;i<n;++i) printf(" %d",i);
for(int i=n-1;i>1;--i) printf(" %d",i);
puts("");
}
return 0;
}