nyoj1032——Save Princess——————【set应用】
Save Princess
- 描述
-
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 sequence1, 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应用】的更多相关文章
- Save Princess(丑数)
Save Princess 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Yesterday, the princess was kidnapped by a de ...
- ZOJ 3369 Saving Princess
Saving Princess Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on ZJU. Origina ...
- [转]Laravel 4之路由
Laravel 4之路由 http://dingjiannan.com/2013/laravel-routing/ Laravel 4路由是一种支持RESTful的路由体系, 基于symfony2的R ...
- NHibernate初步使用
1.创建一个网站项目:QuickStart 2.引用程序集:NHibernate.dll 3.更改配置文件加入以下节点: <configSections> <section name ...
- C# 数据操作系列 - 10 NHibernate初试
0. 前言 在上一篇基本讲完了EF Core的入门级教程.从这一篇开始,我们试着去探索一下 .net core平台上更多的ORM框架.那么,这一篇开始我们就来试试NHibernate. 1. NHib ...
- sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)
Rescue The Princess Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Several days ago, a b ...
- 山东省第四届acm.Rescue The Princess(数学推导)
Rescue The Princess Time Limit: 1 Sec Memory Limit: 128 MB Submit: 412 Solved: 168 [Submit][Status ...
- sdutoj 2603 Rescue The Princess
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2603 Rescue The Princess ...
- SDUT 2603:Rescue The Princess
Rescue The Princess Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Several days ago, a b ...
随机推荐
- 苹果微信内置浏览器cookie
苹果微信内置浏览器cookie会被自动清掉,但safari不会清除,原因还未找到,解决方法是把前端把数据通过header传到后台
- 认识学习MVC这家伙
通过最近的学习认识,只能感慨这玩意太强大了! 以前看了一些MVC的入门教程,看入门教程我感觉不能去体会它的强大,可以看看它的扩展点,通过扩展点去真正的试着了解它,体会它的强大. 它的验证.模型绑定提供 ...
- php CI框架 使用PDO 的连接配置
$db['default'] = array( 'dsn' => 'mysql:dbname=hejun;host=192.168.137.127', //'hostname' => '' ...
- 1222: FJ的字符串 [水题]
1222: FJ的字符串 [水题] 时间限制: 1 Sec 内存限制: 128 MB 提交: 92 解决: 20 统计 题目描述 FJ在沙盘上写了这样一些字符串: A1 = “A” A2 = ...
- NPOI.XWPF生成WORD,设置Table单元格的背景色
tr.GetCell().SetColor("#fbd4b4");
- 查看db连接数sql
/****** Object: StoredProcedure [dbo].[SP_Conn] Script Date: 12/09/2018 19:03:28 ******/ SET ANSI_NU ...
- 为Arch Linux添加鼠标支持(gpm)
gpm的安装 在Arch Linux中安装gpm $ pacman -S gpm 如果你正在使用触控板,需要安装一下插件 $ pacman -S gpm xf86-input-synaptics 需要 ...
- Adobe Fireworks CS5 | Adobe Dreamweaver CS5 | Adobe Photoshop CS5 Extended 绿色精简版最新下载地址
下载地址可能已经不能直接下载,可以用迅雷下载试试 Adobe Photoshop CS5 简体中文绿色版 下载地址:Adobe_Photoshop_CS5_Extended.7z 此绿色版特点:1. ...
- Android RecyclerView组件和 Spinner(下拉列表框)
1.RecyclerView <1>知识点介绍 RecyclerView 比 ListView 更高级且更具灵活性. 它是一个用于显示庞大数据集的容器,可通过保持有限数量的视图进行非常有效 ...
- Ubuntu系统安装WeChat
安装: 1.sudo apt install snapd snapd-xdg-open 2.sudo snap install electronic-wechat 运行: electronic-wec ...