URAL_1789_Searching for the Dodecahedron_机智

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;
}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值