【30.53%】【hdu 5878】I Count Two Three
来源:互联网 发布:淘宝详情页模板网 编辑:程序博客网 时间:2024/05/22 09:35
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 537 Accepted Submission(s): 271
Problem Description
I will show you the most popular board game in the Shanghai Ingress Resistance Team.
It all started several months ago.
We found out the home address of the enlightened agent Icount2three and decided to draw him out.
Millions of missiles were detonated, but some of them failed.
After the event, we analysed the laws of failed attacks.
It's interesting that thei -th attacks failed if and only if i can be rewritten as the form of 2a3b5c7d which a,b,c,d are non-negative integers.
At recent dinner parties, we call the integers with the form2a3b5c7d "I Count Two Three Numbers".
A related board game with a given positive integern from one agent, asks all participants the smallest "I Count Two Three Number" no smaller than n .
It all started several months ago.
We found out the home address of the enlightened agent Icount2three and decided to draw him out.
Millions of missiles were detonated, but some of them failed.
After the event, we analysed the laws of failed attacks.
It's interesting that the
At recent dinner parties, we call the integers with the form
A related board game with a given positive integer
Input
The first line of input contains an integer t (1≤t≤500000) , the number of test cases. t test cases follow. Each test case provides one integer n (1≤n≤109) .
Output
For each test case, output one line with only one integer corresponding to the shortest "I Count Two Three Number" no smaller than n .
Sample Input
1011113123123412345123456123456712345678123456789
Sample Output
11214125125012348123480123480012348000123480000
Source
2016 ACM/ICPC Asia Regional Qingdao Online
【题解】
10^9用2乘就是2^30左右。用3 是3^19,又是5^13,又是7^11;
然后30*19*13*11不会很大!
注意2^0,3^0。。。
然后枚举2,3,5,7的指数。得到一个数字。
我是觉得不会有重复的数字。
但是有也没关系。lower_bound的功能足够解决这道题。
【代码】
#include <cstdio>#include <algorithm>const long long num[5] = { 0,2,3,5,7 };const int limit[5] = { 0,30,19,13,11 };const long long max = 1000000000;long long a[5] = { 0 };long long pre[5][31];long long tt = 1;long long b[90000];int t, n = 0;//max==9void dfs(int now)//dfs枚举质因子的指数{if (tt > max)return;if (now == 5){n++;b[n] = tt;return;}for (int i = 0; i <= limit[now]; i++){long long kk = tt;tt *= pre[now][i];dfs(now + 1);tt = kk;}}int main(){//freopen("F:\\rush.txt", "r", stdin);//freopen("F:\\rush_out.txt", "w", stdout);for (int i = 1; i <= 4; i++)pre[i][0] = 1;for (int i = 1; i <= 4; i++){for (int j = 1; j <= limit[i]; j++)//预处理出2^x,3^y...pre[i][j] = pre[i][j - 1] * num[i];}dfs(1);std::sort(b + 1, b + 1 + n);//排序。之后才能用lower_bound;scanf("%d", &t);long long query;for (int i = 1; i <= t; i++){scanf("%I64d", &query);printf("%I64d\n", b[std::lower_bound(b + 1, b + 1 + n, query) - b]);}return 0;}
0 0
- 【30.53%】【hdu 5878】I Count Two Three
- hdu 5878 I Count Two Three
- HDU 5878 I Count Two Three .
- HDU 5878 - I Count Two Three
- HDU 5878 I Count Two Three
- HDU-5878-I Count Two Three
- 5878 I Count Two Three
- HDU 5878 I Count Two Three (dfs+二分)
- hdu 5878 I Count Two Three(二分)
- HDU 5878 I Count Two Three 2016青岛网赛
- hdu 5878 I Count Two Three 丑数
- HDU 5878 I Count Two Three (DFS预处理 + 二分)
- HDU-5878 I Count Two Three(打表)
- hdu 5878 I Count Two Three【预处理打表+二分】
- 【HDU 5878】I Count Two Three(预处理+二分)
- HDU 5878 I Count Two Three(打表加二分)
- hdu 5878 I Count Two Three 丑数 二分
- HDU-5878-I Count Two Three-预处理+二分
- C# 多线程(一)
- [CODEVS3243]区间翻转(线段树||splay||块链)
- 编辑器(Win记事本、Sublime、Notepad++)对常见字符编码的处理和区别:GB2312、GBK、ANSI、Unicode、UTF-8
- 用户行为日志的统计,Java mapreduce与Scala spark的代码存档...
- 把空格用%20代替
- 【30.53%】【hdu 5878】I Count Two Three
- jxl导出excel提示”文件错误 可能某些数字格式已丢失“解决办法
- Git分支管理策略
- [kuangbin带你飞]专题一 简单搜索 G POJ3087
- Android 解决65535的限制 使用android-support-multidex解决Dex超出方法数的限制问题
- PCA(主城分析法)
- 中文字符编码:GB2312、GBK、ANSI、Unicode、UTF-8
- vtkTextActor的多行显示
- Material Design调色板