一道有意思的acm: 1789. Searching for the Dodecahedron
来源:互联网 发布:win10 软件桌面图标 编辑:程序博客网 时间:2024/06/05 11:59
原文: 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
3
22 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的奇偶, 都可以满足以上条件.
- 一道有意思的acm: 1789. Searching for the Dodecahedron
- 有意思的一道题
- 一道有意思的题目
- 一道有意思的题
- 一道有意思的ACM题——Poker Hands的解法
- 一道有意思的下推自动机题
- 十一道有意思的题
- 一道有意思的计算题
- 一道很有意思的题目
- 一道有意思的C++题目
- Po一道有意思的题
- 一道有意思的概率题
- 一道很有意思的题目
- 一道有意思的逻辑题
- 一道有意思的笔试题
- 一道有意思的概率应用题
- 一道有意思的面试题
- 一道有意思的JAVA题
- OpenCV源码中Haar训练及提取特征的代码
- 电路设计——电容设计
- Kindle刚入华,电子书瞬间被破解!
- Data Structures (Weiss) Chapter 4: Binary Search Tree C++
- 线段树——HDU1255 覆盖的面积解题报告
- 一道有意思的acm: 1789. Searching for the Dodecahedron
- C# JSON 转List<T>类
- 为公司做好长远计划company plan ahead
- DevSuite项目管理平台助力莱芜钢铁集团,有效管控并行项目
- zoj 1095 丑数、1151反转单词、1088 约瑟夫环
- hud 2151 Worm
- Data Structures (Weiss) Chapter 4: AVL Trees 平衡树
- ffmpeg裁剪合并视频
- Html----textarea