hdu 5878 I Count Two Three 丑数 二分

来源:互联网 发布:数据库建库 编辑:程序博客网 时间:2024/05/22 06:26

I Count Two Three

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 649    Accepted Submission(s): 332


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 (1t500000), the number of test cases. t test cases follow. Each test case provides one integer n (1n109).
 

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

不懂得可以搜下丑数的求法。

#pragma comment(linker,"/STACK:124000000,124000000")#include <algorithm>#include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>#include <vector>#include <math.h>#include <queue>#include <set>#include <map>#define lson  i<<1#define rson  i<<1|1#define ll long long#define clr(a,b) memset(a,b,sizeof(a))#define scanfi(a) scanf("%d",&a)#define scanfs(a) scanf("%s",a)#define scanfl(a) scanf("%I64d",&a)#define scanfd(a) scanf("%lf",&a)#define key_val ch[ch[root][1]][0]#define eps 1e-7#define inf 0x3f3f3f3f3f3f3f3fusing namespace std;const int maxn = 10000;int dp[maxn];template<class T> void read(T&num){    char CH;    bool F=false;    for(CH=getchar(); CH<'0'||CH>'9'; F= CH=='-',CH=getchar());    for(num=0; CH>='0'&&CH<='9'; num=num*10+CH-'0',CH=getchar());    F && (num=-num);}int stk[70], tp;template<class T> inline void print(T p){    if(!p)    {        puts("0");        return;    }    while(p) stk[++ tp] = p%10, p/=10;    while(tp) putchar(stk[tp--] + '0');    putchar('\n');}int main(){    int T,n;    scanf("%d",&T);    dp[0] = 1;    int d,d2,d3,d5,d7;    d = 1;    d2 = d3 = d5 = d7 = 0;    while(dp[d-1] < 1e9)    {        int ans;        ans = min(dp[d2]*2, dp[d3]*3);        ans=min(ans,dp[d7]*7);        ans=min(ans,dp[d5]*5);        if (ans == dp[d2]*2)++d2;        if (ans == dp[d3]*3)++d3;        if (ans == dp[d5]*5)++d5;        if (ans==dp[d7]*7)++d7;        dp[d++] = ans;    }    while (T--)    {        scanf("%d",&n);        int pos =lower_bound(dp,dp+5194,n)-dp;        printf("%d\n",dp[pos]);    }    return 0;}



0 0