UVa 136 - Ugly Numbers
题目大意:只有素因子2,3,5的数叫做丑数。输出第1500个丑数即可。
这个...好吧,直接输出就是了。自己写一个小程序先计算一下,这就是黑盒测试的好处啊,“我们的目标是解决问题,而不是为了写程序而写程序,同时应该保持简单(Kepp It Simple and Stupid, KISS)”,摘自《算法竞赛入门经典》。
#include <cstdio> int main()
{
int p = ; // the number of ugly number
int i;
for (i = ; ; i++)
{
int t = i;
while (t % == ) t /= ;
while (t % == ) t /= ;
while (t % == ) t /= ;
if (t == )
{
p++;
//printf("%d is the %dth ugly number\n", i, p);
}
if (p >= ) break;
}
printf("%d\n", i);
return ;
}
这个是暴力枚举测试的,简单直接,不过效率不高,还看到一个用dp解决的,以后在完善啦
忽然想试一下这道题c和c++的差别,就换了一下头文件用c提交,竟然用了12ms,c++才用了9ms,为什么会这样呢?c不是应该比c++快的吗? 2013.7.16
UVa 136 - Ugly Numbers的更多相关文章
- UVA.136 Ugly Numbers (优先队列)
UVA.136 Ugly Numbers (优先队列) 题意分析 如果一个数字是2,3,5的倍数,那么他就叫做丑数,规定1也是丑数,现在求解第1500个丑数是多少. 既然某数字2,3,5倍均是丑数,且 ...
- UVA - 136 Ugly Numbers (有关set使用的一道题)
Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5, 6, 8, 9, ...
- UVA - 136 Ugly Numbers(丑数,STL优先队列+set)
Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3, 4, 5, 6, 8, 9 ...
- UVa 136 Ugly Numbers【优先队列】
题意:给出丑数的定义,不能被除2,3,5以外的素数整除的的数称为丑数. 和杭电的那一题丑数一样--这里学的紫书上的用优先队列来做. 用已知的丑数去生成新的丑数,利用优先队列的能够每次取出当前最小的丑数 ...
- 136 - Ugly Numbers
Ugly Numbers Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3 ...
- 136 Ugly Numbers(priority_queue+逆向求解要求数)
题目链接: https://cn.vjudge.net/problem/UVA-136 /*问题 输出第1500个丑数,丑数的定义是不能被2,3,5以外的其他素数整除的数 解题思路 直接硬暴力先试一下 ...
- 丑数(Ugly Numbers, UVa 136)
丑数(Ugly Numbers, UVa 136) 题目描述 我们把只包含因子2.3和5的数称作丑数(Ugly Number).求按从小到大的顺序的第1500个丑数.例如6.8都是丑数,但14不是,因 ...
- 【UVA - 136】Ugly Numbers(set)
Ugly Numbers Descriptions: Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequ ...
- Ugly Numbers UVA - 136(优先队列+vector)
Problem Description Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, ...
随机推荐
- 剑指offer 复杂链表的复制 (有向图的复制)
时间复杂度O(3N) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ...
- Linux通过防火墙禁止IP来防止攻击
1. iptables -I INPUT -s 211.1.0.0 -j DROP 禁止211.1.0.0这个IP访问服务器 2. iptables -I INPUT -s 211.1.0.0 -j ...
- hprof网络连接
demo/jvmti/hprof/tt/manual.htmlnc -l -k 12321 java -agentpath:./demo/jvmti/hprof/lib/libhprof.so=net ...
- 一个java解析xml的简单例子
java解析xml,主要是通过Dom4j实现的,很多场合都会用到此功能,需要解析XML文件. 下面是一个简单的解析XML文件的例子: import java.util.Iterator; import ...
- CentOS 6.5添加163源
1.首先备份/etc/yum.repos.d/CentOS-Base.repo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS ...
- 开心的金明<0-1背包>
题意:0-1背包经典题: 不多述,直接上代码: 1.二维数组表示法: #include<cstdio> #include<iostream> #include<algor ...
- iOS触摸事件深入
转载自:http://www.cnblogs.com/wengzilin/p/4720550.html 概述 本文主要解析从我们的手指触摸苹果设备到最终响应事件的整个处理机制.本质上讲,整个过程可以分 ...
- thinkphp5.0 生命周期
1.入口文件 // 应用入口文件 index.php // 定义项目路径 define('APP_PATH', __DIR__ . '/../application/'); // 加载框架引导文件 r ...
- rm link
# this works rm foo # versus rm foo/
- CodeForces 606B Testing Robots
模拟,题意看了一小时 /* *********************************************** Author :Zhou Zhentao Email :774388357@ ...