UVA 136 丑数
来源:互联网 发布:金庸小说排名 知乎 编辑:程序博客网 时间:2024/05/29 15:07
题目连接:点击打开链接
题目大意:丑数是除去2,3,5之后不能被其它素数整除的数,求出第1500个素数是多少
思路:优先队列,映射应用,运用优先队列将数字按从小到大排列,之后依次乘以2,3,5,求出丑数,用映射判断丑数是否出现过。
代码:
#include<stdio.h>#include<string.h>#include<vector> #include<queue>#include<map>using namespace std;int main(){int i,j,k,m,n;int b[3]={2,3,5};priority_queue<long long,vector<long long>,greater<long long> > q;map<long long,long long> s;q.push(1);s[1]=1;i=0;long long x;while(i<1500){x=q.top();q.pop();for(j=0;j<3;j++){long long x1=x*b[j];if(!s[x1]) {s[x1]=x1;q.push(x1);}}i++; }printf("The 1500'th ugly number is %lld.\n",x);return 0;}
阅读全文
0 0
- UVa 136 丑数
- uva 136 丑数
- Uva 136 丑数
- uva 136 丑数
- UVA 136 丑数
- UVa 136 丑数
- 丑数 UVa 136
- UVA 136 丑数
- 丑数 uva-136 丑数
- 丑数(UVa 136)
- uva 136 丑数 STL
- HDU 1058||Uva 136 丑数
- Ugly Numbers UVA 136 丑数
- Uva 136 Ugly Numbers(丑数)
- 丑数 (using priority_queue) UVA
- 容器set的应用:丑数 UVA - 136
- 例题5-7 UVA 136 Ugly Numbers丑数(set+优先队列)
- 紫书章五例题七 丑数 UVa 136(多种方法,在这里介绍优先级队列)
- vagrant 安装与配置
- [NOIP模拟][LCA]一样远
- codeforces 602 D. Lipshitz Sequence
- python里使用正则表达式的分组命名方式
- java 常用集合list与Set、Map区别及适用场景总结
- UVA 136 丑数
- 让移动端页面滚动后不触发touchend事件的方法
- jq 城市列表
- jquery ajax的简单使用
- 小游戏:扫雷 (C语言实现扫雷的基本功能)
- Delphi FrieDAC 大数据处理
- python学习--list
- 文章标题
- 类初始化步骤