PAT Basic 1005
2014-10-21 11:37
169 查看
今天的此时此刻是一个特殊的时刻,在这一时刻终于攻克了PAT Basic Level的所有试题,想来从最初接触这个Programming Ablitity Test以来,被题目中的每一个坑深深的坑过,幸好挺过来了,请看第五题的解答,今天心情好说一说程序的思路。那一天我以为使用Python解决这道题很容易,但是陷入了一个Python的误解中……开始的时候总是以为链表的reverse就是逆序输出,其实不然,这个函数只是将链表的内容逆序而已,所以,在调用这个函数之前又排了一次序。
1005. 继续(3n+1)猜想 (25)
时间限制400 ms
内存限制
32000 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
卡拉兹(Callatz)猜想已经在1001中给出了描述。在这个题目里,情况稍微有些复杂。
当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数。例如对n=3进行验证的时候,我们需要计算3、5、8、4、2、1,则当我们对n=5、8、4、2进行验证的时候,就可以直接判定卡拉兹猜想的真伪,而不需要重复计算,因为这4个数已经在验证3的时候遇到过了,我们称5、8、4、2是被3“覆盖”的数。我们称一个数列中的某个数n为“关键数”,如果n不能被数列中的其他数字所覆盖。
现在给定一系列待验证的数字,我们只需要验证其中的几个关键数,就可以不必再重复验证余下的数字。你的任务就是找出这些关键数字,并按从大到小的顺序输出它们。
输入格式:每个测试输入包含1个测试用例,第1行给出一个正整数K(<100),第2行给出K个互不相同的待验证的正整数n(1<n<=100)的值,数字间用空格隔开。
输出格式:每个测试用例的输出占一行,按从大到小的顺序输出关键数字。数字间用1个空格隔开,但一行中最后一个数字后没有空格。
输入样例:
6 3 5 6 7 8 11
输出样例:
7 6
#!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014年9月16日 @author: qcq acquired help from: cxp The description of this file: #English# The reason to write this file, what contains in this file. What is the most import function in this file or what specific algorithm implemented in this file's code. N: The important common parameters should list here. The change records: Time Changed By Reason 2014年9月16日 qcq ... ... ... ''' def CutNumber(temp): global data data.append(temp) while temp > 1: if 0 == temp % 2: temp = temp / 2 data.append(temp) else: temp = (3 * temp + 1) / 2 data.append(temp) if __name__ == '__main__': data = [] temp1 = [] a = int(raw_input().strip()) b = raw_input().strip().split(' ') for index in range(a): data = [] for index_2 in range(a): if index_2 != index: CutNumber(int(b[index_2])) if data.count(int(b[index])): break; if 0 == data.count(int(b[index])): temp1.append(int(b[index])) temp1.sort() temp1.reverse() string = '' for i in temp1: string+=str(i) + ' ' string = string[0:len(string) - 1] print string
相关文章推荐
- PAT(BASIC)1005 继续3n+1猜想
- PAT (Basic Level) Practise (中文) 1005继续(3n+1)猜想 (25)
- 刷题训练——PAT(Basic Level)-1005
- PAT (Basic Level) Practise 的C++实现-1005.继续(3n+1)猜想
- PAT(Basic Level)_1005_继续(3n+1)猜想
- PAT Basic 1005. 继续(3n+1)猜想 (25)(C语言实现)
- PAT (Basic Level) Practise (中文)1005. 继续(3n+1)猜想 (25) C语言
- Pat(Basic Level)Practice--1005(继续3n+1猜想)
- PAT Basic Level 1005. 继续(3n+1)猜想 (25)
- PAT BASIC LEVEL 1005. 继续(3n+1)猜想 (25)
- PAT (Basic Level) Practise (中文)- 1005. 继续(3n+1)猜想 (25)
- PAT (Basic Level) Practise:1005. 继续(3n+1)猜想
- PAT (Basic Level) Practise (中文)1005. 继续(3n+1)猜想 (25)
- PAT (Basic Level) Practise (中文)1005. 继续(3n+1)猜想 (25)
- PAT乙级真题及训练集 PAT (Basic Level) Practise (中文)1005. 继续(3n+1)猜想
- 【C++】浙大PAT (Basic Level)1005. 继续(3n+1)猜想 (25)
- PAT basic1001-1005(Python版)
- PAT乙级(Basic Level)真题-1005 德才论 (25)
- PAT1005(BASIC)
- 浙江大学PAT---Basic Level---1005----继续(3n+1)猜想