2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分
2016-09-21 20:56
447 查看
I Count Two Three
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 782 Accepted Submission(s): 406
[align=left]Problem Description[/align]
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 the i-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 form 2a3b5c7d "I Count Two Three Numbers".
A related board game with a given positive integer n from one agent, asks all participants the smallest "I Count Two Three Number" no smaller than n.
[align=left]Input[/align]
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).
[align=left]Output[/align]
For each test case, output one line with only one integer corresponding to the shortest "I Count Two Three Number" no smaller than n.
[align=left]Sample Input[/align]
10
1
11
13
123
1234
12345
123456
1234567
12345678
123456789
[align=left]Sample Output[/align]
1
12
14
125
1250
12348
123480
1234800
12348000
123480000
[align=left]Source[/align]
2016 ACM/ICPC Asia Regional Qingdao Online
题意: t组数据 给你一个n 输出不小于n的最短的数x
x=2^a*3^b*5^c*7^d
题解:因为最大为1e9 先打表找到所有的满足条件的数x 之后二分答案
/****************************** code by drizzle blog: www.cnblogs.com/hsd-/ ^ ^ ^ ^ O O ******************************/ #include<bits/stdc++.h> #include<iostream> #include<cstring> #include<cmath> #include<cstdio> #define ll long long #define mod 1000000007 #define PI acos(-1.0) #define N 1000000000 using namespace std; int t; ll a2[35]={1},a3[35]={1},a5[35]={1},a7[35]={1}; int jishu; ll ans[50005]; void init() { jishu=0; int er=0,san=0,wu=0,qi=0; for(int i=1; a2[i-1]<=N;er++,i++) a2[i]=a2[i-1]*2; for(int i=1; a3[i-1]<=N;san++,i++) a3[i]=a3[i-1]*3; for(int i=1; a5[i-1]<=N;wu++,i++) a5[i]=a5[i-1]*5; for(int i=1; a7[i-1]<=N;qi++, i++) a7[i]=a7[i-1]*7; for(int i=0; i<er; i++) for(int j=0; a2[i]*a3[j]<=N&&j<san; j++) for(int k=0; a2[i]*a3[j]*a5[k]<=N&&k<wu; k++) for(int l=0; a2[i]*a3[j]*a5[k]*a7[l]<=N&&l<qi; l++) ans[jishu++]=a2[i]*a3[j]*a5[k]*a7[l]; sort(ans,ans+jishu); } int main() { int n; while(scanf("%d",&t)!=EOF) { init(); for(int i=1; i<=t; i++) { scanf("%d",&n); printf("%I64d\n",ans[lower_bound(ans,ans+jishu,n)-ans]); } } return 0; }
相关文章推荐
- 2016 ACM/ICPC Asia Regional Qingdao Online 1001 I Count Two Three(打表+二分搜索)
- HDU5878 Cure 2016 ACM/ICPC Asia Regional Qingdao Online
- 2016 ACM/ICPC Asia Regional Qingdao Online hdu 5884 Sort (二分+优先队列)★
- HDU 5878 -- 丑数打表(2016 ACM/ICPC Asia Regional Qingdao Online)
- hdu 5878 I Count Two Three (2016 ACM/ICPC Asia Regional Qingdao Online 1001)
- 2016 ACM/ICPC Asia Regional Qingdao Online 1001
- [Contests]2016 ACM/ICPC Asia Regional Qingdao Online(1001/2/4/5/6)
- hdu--5878(hdu 5878 I Count Two Three (2016 ACM/ICPC Asia Regional Qingdao Online 1001))
- HDU 5878 -- 丑数打表(2016 ACM/ICPC Asia Regional Qingdao Online)
- HDU 5878 I Count Two Three (2016 ACM/ICPC Asia Regional Qingdao Online 1001)
- HDU 5878 I Count Two Three 2016 ACM/ICPC Asia Regional Qingdao Online 1001
- 2016 ACM/ICPC Asia Regional Qingdao Online
- 2016 ACM/ICPC Asia Regional Dalian Online 1008 Function 二分+RMQ
- HDU 5878 I Count Two Three (暴力) 2016 ACM/ICPC Asia Regional Qingdao Online
- HDU 5875 Function(二分区间+RMQ)——2016 ACM/ICPC Asia Regional Dalian Online
- HDU 5879 Cure 2016 ACM/ICPC Asia Regional Qingdao Online 1002
- 2016 ACM/ICPC Asia Regional Qingdao Online(Balanced Game)
- HDU 5881 Tea (水题) 2016 ACM/ICPC Asia Regional Qingdao Online
- HDU 5879 Cure(技巧)——2016 ACM/ICPC Asia Regional Qingdao Online
- HDU 5883 The Best Path (欧拉通路) 2016 ACM/ICPC Asia Regional Qingdao Online