http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010

http://poj.org/problem?id=1338

首先poj这题要找出第n个丑数,想到要打表,因为每一个丑数都是由前一个丑数*2或者*3或者*5得到,每次取3种结果种较小的那一个放入数组中.

打表的时候要注意保持数组有序.

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
//#pragma comment(linker, "/STACK:102400000,102400000")
#define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("b.txt", "w", stdout);
#define maxn 1010
#define maxv 1010
#define mod 1000000000
using namespace std;
ll p[];
int main()
{
//freopen("a.txt","r",stdin);
int i=,j=,k=;
p[]=;
for(int l=;l<=;l++)
{
p[l]=min(p[i]*,min(p[j]*,p[k]*));
if(p[l]==p[i]*) i++;
if(p[l]==p[j]*) j++;
if(p[l]==p[k]*) k++;
//printf("%lld\n",p[l]);
}
int n;
while(~scanf("%d",&n)&&n)
{
printf("%lld\n",p[n]);
}
return ;
}

51nod这题让你求>=n的丑数,因为n很大,所以打完表后需要二分查找,打表的时候要注意直到大于10^18,上限可以自己试几次.

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
//#pragma comment(linker, "/STACK:102400000,102400000")
#define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("b.txt", "w", stdout);
#define maxn 1010
#define maxv 1010
#define mod 1000000000
using namespace std;
ll p[]; ll erfen(ll n)
{
int l=,r=;
while(l<=r)
{
int mid=(l+r)/;
if(p[mid]==n) return p[mid];
else if(p[mid]>n) r=mid-;
else l=mid+;
}
if(p[l]<n) l++;
return p[l];
}
int main()
{
freopen("a.txt","r",stdin);
int i=,j=,k=;
p[]=;
for(int l=;l<=;l++)
{
p[l]=min(p[i]*,min(p[j]*,p[k]*));
if(p[l]==p[i]*) i++;
if(p[l]==p[j]*) j++;
if(p[l]==p[k]*) k++;
//printf("%lld\n",p[l]);
}
//printf("%lld\n",p[10000]);
int t;
ll n;
scanf("%d",&t);
while(t--)
{
scanf("%lld",&n);
{
if(n==) printf("2\n");
else
printf("%lld\n",erfen(n));
}
}
return ;
}

51nod 1010 只包含因子2 3 5的数 && poj - 1338 Ugly Numbers(打表)的更多相关文章

  1. 51nod 1010 只包含因子2 3 5的数 二分答案

    1010 只包含因子2 3 5的数 K的因子中只包含2 3 5.满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15. 所有这样的K组成了一个序列S,现在给出一个数n,求S中 > ...

  2. 51nod 1010 只包含因子2 3 5的数 打表

    只包含因子2 3 5的数 题目连接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010 Description K的 ...

  3. 51Nod 1010 只包含因子2 3 5的数 Label:None

    K的因子中只包含2 3 5.满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15. 所有这样的K组成了一个序列S,现在给出一个数n,求S中 >= 给定数的最小的数. 例如:n = ...

  4. 51Nod 1010 只包含因子2 3 5的数

    K的因子中只包含2 3 5.满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15. 所有这样的K组成了一个序列S,现在给出一个数n,求S中 >= 给定数的最小的数. 例如:n = ...

  5. 51Nod 1010 只包含因子2 3 5的数(打表+二分)

    K的因子中只包含2 3 5.满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15. 所有这样的K组成了一个序列S,现在给出一个数n,求S中 >= 给定数的最小的数. 例如:n = ...

  6. 51Nod 1010 只包含因子2 3 5的数 | 预处理+二分

    Input示例 5 1 8 13 35 77 Output示例 2 8 15 36 80 分析:将所有的只含有2 3 5因子的数打一个表保存在一个数组里,然后二分查找第一个>=数组里的数,输出 ...

  7. 1007 正整数分组 1010 只包含因子2 3 5的数 1014 X^2 Mod P 1024 矩阵中不重复的元素 1031 骨牌覆盖

    1007 正整数分组 将一堆正整数分为2组,要求2组的和相差最小. 例如:1 2 3 4 5,将1 2 4分为1组,3 5分为1组,两组和相差1,是所有方案中相差最少的.   Input 第1行:一个 ...

  8. 只包含因子2 3 5的数(51NOD 1010)

    K的因子中只包含2 3 5.满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15. 所有这样的K组成了一个序列S,现在给出一个数n,求S中 >= 给定数的最小的数. 例如:n = ...

  9. 把只包含因子2、3和5的数称作丑数(Ugly Number)。例如6、8都是丑数,但14不是,因为它包含因子7。 习惯上我们把1当做是第一个丑数。求按从小到大的顺序的第N个丑数。

    // ConsoleApplication1.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> ...

随机推荐

  1. Oracle中的日期数据类型

    TimeStamp日期类型 TimeStamp数据类型用于存储日期的年.月.日,以及时间的小时.分和秒,其中秒值精确到小数点后6位,该数据类型 同时包含时区信息.systimestamp函数的功能是返 ...

  2. 架构师细说 NGINX 的配置及优化

    最近感觉很多东西在运用到一定的程度之后,会发现原来是自己了解到的不够.一方面限于实际运用到的不多,一方面可能是因为一开始没有进行全面认识.遂这里搜集整理了一番NGINX. 一.nginx启动和关闭 c ...

  3. SQL Server xtype的介绍

    sysobjects 表 在数据库内创建的每个对象(约束.默认值.日志.规则.存储过程等)在表中占一行.只有在 tempdb 内,每个临时对象才在该表中占一行. 列名 数据类型 描述 name sys ...

  4. 迅为iTOP-4418/6818开发板MiniLinux下的GPS使用手册

    平台:iTOP-4418/6818开发板 系统:MiniLinux 在 Mini Linux 系统环境下 iTOP-4418 和 6818 的 GPS 实验调试步骤.给用户提供了“iTOP-4418- ...

  5. GIT 获取指定历史版本代码

    cd 到该项目的一个本地仓库下 log 查看提交记录,找到想要的提交记录,粘贴对应的希哈值 执行 git checkout 希哈值 这本地的这个仓库的代码就会变成你想要的那个版本的代码

  6. 扩展IHttpHandler

    前面提到当请求进入到IIS,IIS转发给ISAPI后会根据文件的后缀名来决定将请求转发给对应的处理程序进行处理,当然一大部分的处理都是交给了AspNet_ISAPI 了.但是,AspNet_ISAPI ...

  7. vue工程化引入组件模板

    vue脚手架搭建好项目后,组件间的引用通过components import bannerComponent from './banner' export default { data(){ retu ...

  8. win7 命令行禁用开启usb存储

    禁用: reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\usbstor" /v Start /t reg ...

  9. JavaScript:JSON 和 JS 对象

    区别 JSON(JavaScript Object Notation)仅仅是一种数据格式(或者叫数据形式).数据格式其实就是一种规范,按照这种规范来存诸和交换数据.就好像 XML 格式一样. 区别 J ...

  10. ERROR 1133 (42000): Can't find any matching row in the user table

    环境:操作系统:Redhat 7.5 x86-64 数据库版本MySQL 5.7.25 现象:ERROR 1133 (42000): Can't find any matching row in th ...