Differences between revisions 4 and 6 (spanning 2 versions)
Revision 4 as of 2006-01-31 15:40:15
Size: 1177
Editor: 143
Comment:
Revision 6 as of 2011-08-03 11:01:00
Size: 688
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
--- ["yong27"] 님 감사합니다. --- [[yong27]] 님 감사합니다.
Line 32: Line 32:
속도를 재서 다른 분들과 비교해 봤습니다. input이 1 999999 일때.

||작성자 ||||<style="TEXT-ALIGN: center">걸린시간 ||||<style="TEXT-ALIGN: center"> [Psyco]를 쓴 후 걸린 시간||
||mgenome ||||<style="TEXT-ALIGN: center">164초 ||||<style="TEXT-ALIGN: center">10초 ||
||yong27 ||||<style="TEXT-ALIGN: center">82초 ||||<style="TEXT-ALIGN: center">8.6초 ||
||windist ||||<style="TEXT-ALIGN: center">9.5초 ||||<style="TEXT-ALIGN: center">3.5초 ||

[Recursion]을 써서 만들었습니다.

--- yong27 님 감사합니다.

   1 def ThreePlusOne(n, count=0):
   2     count += 1
   3     if n==1:
   4         return count
   5     elif n%2==0:
   6         return ThreePlusOne(n/2, count) # return을 빼먹으면 None이  리턴
   7     else:
   8         return ThreePlusOne(n*3+1, count) #return을 빼먹으면 None이 리턴
   9         
  10 def main():
  11     i, j = raw_input().split()
  12 
  13     b = 0
  14     for a in range(int(i), int(j)+1):
  15         temp = ThreePlusOne(a)
  16         if b < temp: b = temp
  17     print i, j, b
  18 
  19 if __name__ == '__main__':
  20     #import psyco
  21     #psyco.bind(main)
  22     main()

3N+1Problem 참조

AlgorithmQuiz/3Plus1/mgenome (last edited 2013-08-09 16:13:17 by 61)

web biohackers.net