Save Princess

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
 
描述
Yesterday, the princess was kidnapped by a devil. The prince has to rescue our pretty princess.
 
"OK, if you want to save the beautiful princess, you must answer my questions correctly."the devil says.
 
"No problem!".
 
"I’ll ask you t questions. For each question, I’ll tell you an integer n, you must tell me the i th beatuiful number. If your answer is wrong, the princess and you will all die".
 
"But what is the characteristic of the beautiful number?" Pince asks.
 
"Beautiful numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 
1, 2, 3, 4, 5, 6, 8, 9, 10, ...   shows the first 9 beautiful numbers.  
By convention, 1 is included. "
 
Can you help the prince to save the princess?
 
输入
The input for each case is an integer n(1≤n≤5000) and it is terminated by a negative integer.
输出
For each test case, you should print an integer which represents the i th beautiful number.
样例输入
2
3
-1
样例输出
2
3 解题思路:用优先队列来存放美丽数,每次从队列中拿出最小的美丽数,由它扩展出三个美丽数,用set的去重功能来判断是否放入set和优先队列。依次从优先队列中出来的就是从小到大的美丽数。
#include<stdio.h>
#include<string.h>
#include<set>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
const int f[4]={2,3,5};
LL a[5500];
void prin(int n){ priority_queue<LL,vector<LL>,greater<LL> >pq;
set<LL>s;
pq.push(1);
s.insert(1);
for(int i=1;;i++){ LL tm=pq.top();
a[i]=tm;
pq.pop();
if(i>n)
break;
for(int i=0;i<3;i++){ LL x=tm*f[i];
if(!s.count(x)){//返回元素x的个数 s.insert(x);
pq.push(x);
}
}
} }
int main(){ int n;
prin(5010);
while( scanf("%d",&n)!=EOF&&n>0){ printf("%lld\n",a[n]);
}
return 0;
}

  

nyoj1032——Save Princess——————【set应用】的更多相关文章

  1. Save Princess(丑数)

    Save Princess 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Yesterday, the princess was kidnapped by a de ...

  2. ZOJ 3369 Saving Princess

    Saving Princess Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on ZJU. Origina ...

  3. [转]Laravel 4之路由

    Laravel 4之路由 http://dingjiannan.com/2013/laravel-routing/ Laravel 4路由是一种支持RESTful的路由体系, 基于symfony2的R ...

  4. NHibernate初步使用

    1.创建一个网站项目:QuickStart 2.引用程序集:NHibernate.dll 3.更改配置文件加入以下节点: <configSections> <section name ...

  5. C# 数据操作系列 - 10 NHibernate初试

    0. 前言 在上一篇基本讲完了EF Core的入门级教程.从这一篇开始,我们试着去探索一下 .net core平台上更多的ORM框架.那么,这一篇开始我们就来试试NHibernate. 1. NHib ...

  6. sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)

    Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a b ...

  7. 山东省第四届acm.Rescue The Princess(数学推导)

    Rescue The Princess Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 412  Solved: 168 [Submit][Status ...

  8. sdutoj 2603 Rescue The Princess

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2603 Rescue The Princess ...

  9. SDUT 2603:Rescue The Princess

    Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a b ...

随机推荐

  1. React 使用browserHistory项目访问404问题

    最近项目里面用到了React但是发布到iis站点之后,路由地址 刷新访问直接404错误.查阅资料之后发现是iis缺少配置URL重写 的问题导致的.下面我们来图形化配置,简单的配置下IIS 打开IIS使 ...

  2. 【转】检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件失败,原因是出现以下错误: 80070005 拒绝访问

    源地址:https://www.cnblogs.com/love522/p/4462253.html 最近在做一个网站时,有一个下载word文档功能,在本地直接调试是可以下载的,但部署到IIS上就出现 ...

  3. 关于函数传参的其他问题(const形参实参/可变形参)

    const 形参和实参 当形参是 const 变量时,实参是 const 或者不是 const 变量都可以. 实参初始化形参时会忽略掉顶层 const: void gel(const int a){ ...

  4. const 迭代器和 const_iterator (vector/set/map)

    vector: 如同一般复合类型一样,vector 迭代器也可以声明成: const vector<int>::iterator it1 = v.begin(); vector<in ...

  5. 【SSO单点系列】(7):CAS4.0 SERVER通过数据库方式认证用户

    在前几篇中有简单介绍服务端的认证方式,默认的是直接在 deployerConfigContext.xml 文件中 一个叫做 primaryAuthenticationHandler 的bean中配置. ...

  6. JavaWeb学习笔记(十)—— JavaBean总结【转】

    一.什么是JavaBean JavaBean是一个遵循特定写法的Java类,它通常具有如下特点: 这个Java类必须具有一个无参的构造函数 属性必须私有化. 私有化的属性必须通过public类型的方法 ...

  7. JavaWeb学习笔记(一)—— Http协议

    一.什么是HTTP协议 HTTP,超文本传输协议(HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议,它是TCP/IP协议的一个应用层协议,用于定义WEB浏览 ...

  8. node.js express 启用 https

    服务端和客户端各有一对公钥和私钥,使用公钥加密的数据只能用私钥解密,建立https传输之前,客户端和服务端互换公钥.客户端发送数据前使用服务端公钥加密,服务端接收到数据后使用私钥解密,反之亦如此. 公 ...

  9. C++_类入门1-对象和类的介绍

    面向对象是(OOP)是特殊的.设计程序的概念性方法:包含以下特性: 抽象: 封装和数据隐藏: 多态: 继承: 代码的可重用性: 为了实现这些特性并且将这些特性组合在一起,C++所做的最重要的改进是提供 ...

  10. angular model-dialog 关闭按钮

    <button class="close" data-dismiss="modal" type="button" aria-label ...