UVa OJ 100-The 3n+1 Problem
2011-01-13 15:02
507 查看
简单,不解释,一开始TLE,加个哈希就AC:
{ Author:wzx961008 Problem:UVa 100-The 3n+1 problem Verdict:Accepted Language:PASCAL Run Time:0.044s Submission Date:2011-01-11 12:06:03 } const maxnum=1000000; var i,l,r,maxT,tmp:longint; hash:array[1..maxnum]of longint; function find(n:qword):longint; begin if n>maxnum then if n and 1=1 then exit(find(3*n+1)+1) else exit(find(n shr 1)+1); if hash =0 then if n and 1=1 then hash :=find(3*n+1)+1 else hash :=find(n shr 1)+1; find:=hash ; end; function max(a,b:longint):longint; begin if a>b then exit(a) else exit(b); end; procedure doit(l,r:longint); begin hash[1]:=1; for i:=l to r do begin tmp:=find(i); if tmp>maxT then maxT:=tmp; end; end; begin while not eof do begin readln(l,r); maxT:=0; if l>r then doit(r,l) else doit(l,r); writeln(l,' ',r,' ',maxT); end; end.
相关文章推荐
- 100 - The 3n + 1 problem Form UVa OJ
- UVa Problem 100 The 3n+1 problem (3n+1 问题)+1 问
- UVA 100 - The 3n+1 problem (3n+1 问题)
- 【转】UVa Problem 100 The 3n+1 problem (3n+1 问题)——(离线计算)
- UVa 100 Problem: The 3n+1 problem (PC 110101)
- UVA 100 The 3n+1 Problem
- UVA 100 - The 3n+1 Problem
- Uva 100 The 3n+1 problem
- UVA 100 - The 3n+1 problem (3n+1 问题)
- UVa Problem Solution: 100 - The 3n+1 problem
- uva 100 The 3n+1 problem
- PC/UVa 题号: 110101/100 The 3n+1 problem (3n+1 问题)
- POJ 1207,UVA 100 The 3n+1 problem
- uva 100 The 3n+1 problem
- UVa Problem 100 The 3n+1 problem (3n+1 问题)
- UVA_100_The_3n+1_Problem
- UVa 100|The 3n+1 Problem|暴力|坑点多
- UVa Problem 100 The 3n+1 problem (3n+1 问题)
- UVa 100 - The 3n + 1 problem
- UVa100 The 3n + 1 problem