一道有意思的acm: 1789. Searching for the Dodecahedron

原文:  http://acm.timus.ru/problem.aspx?space=1&num=1789


背景:  有一具有魔力的寶石藏在1,2,3...n. 只石像中, 嘗試去尋找它:

  1) 如果該石像中含有, 那麼寶石得到;

  2)如果該石像中沒有, 那麼寶石將會向其相鄰的石像中跳移過去(石像的排列方式是 從左至右,線性排列) .  向左或者向右是隨機的. 


對於一個給定的n, 請給出一套完備確定能找到寶石的尋找方案. 


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.

Sample

input output
3
2
2 2
Problem Author: Mikhail Rubinchik 


思路: 


先從小數值的n開始.  

 n = 2 ,   2 2

 n = 3 ,   2 2


 n = 4  \  5?  

想到這裏 覺得這種枚舉找規律的方式可能不適合這個題, 因此轉變了思路,  對於原題目中的 如果找不到則向左向右轉移1個距離  那麼連續兩次轉移不變的是什麼??

 -- > 位置的奇偶特性.   

  

如果原來寶石所在位置是偶數(even) ,那麼說明

 第1次,3次,... (2n+1)次尋找時 寶石在偶數位置   所以你的輸出解中 奇數位置上的需要是偶數 ,  偶數位置需要是奇數 


 同理, 如果原始位置是奇數(odd) ==>  你的輸出解中 奇數位置上的需要是奇數 ,  偶數位置需要是偶數  .   


所以爲了綜合包容以上兩種情況,  一個完備的方案是: 具備 奇數位置奇數序列 1,3,5,....  | 奇數位置位數序列 2,4,6, ... ; 也具備偶數位置上的兩個子列. 


因此一種設計方案可以是 


1,2,3,4,5... n ; n, (n-1) , ... 1 


這樣一個序列 無論n的奇偶, 都可以滿足以上條件. 











發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章