poj1338
来源:互联网 发布:手机淘宝客服在哪 编辑:程序博客网 时间:2024/05/16 19:14
【题意】
回答第n个丑数是多少
丑数即为质因数只有2、3、5的数
【输入】
多次询问,询问以一个0结束
每次询问只有一个n
【输出】
回答每次询问
这个预处理一下前1500个丑数,回答的时候直接回答就好了
我挂了个堆来生成丑数,实际上没必要……
program poj1338;var all,tot,n,i,j,k:longint; ans:array [0..1501] of int64; heap:array [0..10001] of int64;procedure swap (var a,b:int64)inline;var i:int64;begin i:=a; a:=b; b:=i;end;procedure insert (now:int64);inline;var i:longint;begin inc(tot); heap[tot]:=now; i:=tot; while (i>1)and(heap[i]<heap[i div 2]) do begin swap(heap[i],heap[i div 2]); i:=i div 2; end;end;procedure delete;inline;var i:longint;begin if tot=1 then begin heap[1]:=heap[0]; dec(tot); exit; end; swap(heap[1],heap[tot]); heap[tot]:=heap[0]; dec(tot); i:=1; while (heap[i*2]<heap[i])or(heap[i*2+1]<heap[i]) do if heap[i*2]<heap[i*2+1] then begin swap(heap[i],heap[i*2]); i:=i*2; end else begin swap(heap[i],heap[i*2+1]); i:=i*2+1; end;end;begin fillchar(heap,sizeof(heap),63); tot:=0; ans[1]:=1; insert(2); insert(3); insert(5); for i:=2 to 1500 do begin while heap[1]=ans[i-1] do delete; ans[i]:=heap[1]; delete; insert(ans[i]*2); insert(ans[i]*3); insert(ans[i]*5); end; repeat read(n); if n=0 then break; writeln(ans[n]); until false;end.
- poj1338
- poj1338
- POJ1338
- poj1338
- poj1338
- poj1338
- POJ1338||POJ2247
- poj1338 poj2591 poj2545 这三道题
- POJ1338解题报告
- poj1338(Ugly Numbers)
- poj 2425&&poj1338
- poj1338 Ugly Numbers(技巧)
- 枚举 poj1338 Ugly Numbers
- POJ1338 Ugly Numbers
- poj1338 Ugly Numbers
- POJ1338 Ugly Numbers
- POJ1338 Ugly Numbers
- poj1338--poj2545--poj2591--打表
- Linux线程经验
- android 详细信息显示界面的思路
- Nginx学习
- 自定义Lamda表达式作为筛选条件
- Struts2 jdbc 增删改查
- poj1338
- 着色语言基础介绍
- UltraEdit 的复制、粘贴功能,其他几个使用小技巧
- windows azure试用感受2
- javascript 编程注意事项
- How to stop a NSThread sub-thread in iphone
- android之程序自动更新的实现
- MySQL海量数据优化
- c# 面向对象笔记(1)