hdu 5878 I Count Two Three【预处理打表+二分】
2016-09-18 20:58
429 查看
I Count Two Three
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3582 Accepted Submission(s): 1094
[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
题目大意:
给你一个数n,让你求一个大于等于n的最小的满足题意中2^a*3^b*5^c*7^d的数字。
思路:
1、很明显,2^32大于了1000000000,那么我们可以O(32^4)预处理出来所有满足这个条件的数。
2、那么我们再对每一个输入的数,二分查找最优解即可(大于等于n的最近数值)
Ac代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll __int64
ll ans[100000];
ll poww(ll di,ll ci)
{
if(ci==-1)return 0;
ll ans=1;
for(int i=1;i<=ci;i++)
{
ans*=di;
}
return ans;
}
void init()
{
int cont=0;
for(int i=0;i<32;i++)
{
if(poww(7,i)>1000000000)break;
for(int j=0;j<32;j++)
{
if(poww(7,i)*poww(5,j)>1000000000)break;
for(int k=0;k<32;k++)
{
if(poww(7,i)*poww(5,j)*poww(3,k)>1000000000)break;
for(int l=0;l<32;l++)
{
ll tmpp=poww(2,l)*poww(3,k)*poww(5,j)*poww(7,i);
if(tmpp>1000000000)break;
ans[cont++]=tmpp;
}
}
}
}
}
int main()
{
int t;
init();
sort(ans,ans+5999);
scanf("%d",&t);
while(t--)
{
ll n;
scanf("%I64d",&n);
int l=0,r=6000;
int mid;
ll anss;
while(r>=l)
{
int mid;
mid=(l+r)/2;
if(ans[mid]<n)
{
l=mid+1;
}
else
{
anss=ans[mid];
r=mid-1;
}
}
printf("%I64d\n",anss);
}
}
相关文章推荐
- HDU 5878 I Count Two Three (预处理+二分查找)
- HDU-5878-I Count Two Three-预处理+二分
- 【HDU 5878】I Count Two Three(预处理+二分)
- HDU 5878 I Count Two Three (打表+二分查找) -2016 ICPC 青岛赛区网络赛
- HDU 5878 I Count Two Three (DFS预处理 + 二分)
- HDU 5878 I Count Two Three(打表加二分)
- HDU 5878 I Count Two Three(打表)qingdao网赛
- HDU 5878 I Count Two Three (dfs+二分)
- hdu_5878_I Count Two Three(预处理)
- hdu 5878 I Count Two Three 丑数 二分
- HDU 5878 I Count Two There(打表预处理)
- hdu 5878 I Count Two Three(二分)
- HDOJ 5878 I Count Two Three 【2016青岛网赛】暴力打表+二分枚举
- HDU-5878 I Count Two Three(打表)
- HDU 5878 I Count Two Three(2016亚洲区青岛站网络赛)
- I Count Two Three---hdu5878(打表+二分)
- 2016 ACM/ICPC Asia Regional Qingdao Online 1001 I Count Two Three(打表+二分搜索)
- hdu I Count Two Three(二分查找&&打表)
- hdu 5878 I Count Two Three
- 1001 I Count Two Three(打表+二分 用lower_bound函数)