2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分

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

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 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.

 
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
10
1
11
13
123
1234
12345
123456
1234567
12345678
123456789
 
Sample Output
1
12
14
125
1250
12348
123480
1234800
12348000
123480000
 
Source
 
题意: 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[]={},a3[]={},a5[]={},a7[]={};
int jishu;
ll ans[];
void init()
{
jishu=;
int er=,san=,wu=,qi=;
for(int i=; a2[i-]<=N;er++,i++)
a2[i]=a2[i-]*;
for(int i=; a3[i-]<=N;san++,i++)
a3[i]=a3[i-]*;
for(int i=; a5[i-]<=N;wu++,i++)
a5[i]=a5[i-]*;
for(int i=; a7[i-]<=N;qi++, i++)
a7[i]=a7[i-]*;
for(int i=; i<er; i++)
for(int j=; a2[i]*a3[j]<=N&&j<san; j++)
for(int k=; a2[i]*a3[j]*a5[k]<=N&&k<wu; k++)
for(int l=; 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=; i<=t; i++)
{
scanf("%d",&n);
printf("%I64d\n",ans[lower_bound(ans,ans+jishu,n)-ans]);
}
}
return ;
}
 
上一篇:赛码网算法: 军训队列( python实现 )


下一篇:详细解析Java中抽象类和接口的区别(转)