2016 ACM/ICPC Asia Regional Qingdao Online 1001 I Count Two Three

Posted Annetree的博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2016 ACM/ICPC Asia Regional Qingdao Online 1001 I Count Two Three相关的知识,希望对你有一定的参考价值。

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

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
10
1
11
13
123
1234
12345
123456
1234567
12345678
123456789
 


Sample Output
1
12
14
125
1250
12348
123480
1234800
12348000
123480000
 
先打表,然后二分搜索做
 1 #include <iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cmath>
 5 #include<cstdlib>
 6 #include<set>
 7 using namespace std;
 8 int t,x,len;
 9 int arr[6000];
10 int main()
11 {
12     len=0;
13   for(int a=0;a<=32;a++)
14   {
15       double aa=pow(2.0,a*1.0);
16       for(int b=0;b<=19;b++)
17       {
18           double bb=pow(3.0,b*1.0);
19           if (aa*bb>=1200000000.0) break;
20           for(int c=0;c<=14;c++)
21           {
22               double cc=pow(5.0,c*1.0);
23               if (aa*bb*cc>=1200000000.0) break;
24               for(int d=0;d<=11;d++)
25               {
26                   double dd=pow(7.0,d*1.0);
27                   if (aa*bb*cc*dd>=1200000000.0) break;
28                   arr[++len]=(int)aa*bb*cc*dd;
29               }
30           }
31       }
32   }
33   sort(arr+1,arr+len+1);
34   //printf("%d\n",arr[len]);
35     //for(int i=1;i<=len;i++) printf("%d ",arr[i]);
36    // printf("%d\n",len);
37     while(scanf("%d",&t)!=EOF)
38     {
39         for(;t>0;t--)
40         {
41             scanf("%d",&x);
42 
43 //            set<int> s;
44 //            s.insert(1);
45 //            while(!s.empty())
46 //            {
47 //                set<int>::iterator ii;
48 //                ii=s.begin();
49 //                if (*ii>=x) {printf("%d\n",*ii); break;}
50 //                s.erase(s.begin());
51 //                int k=*ii;
52 //                if(k*2<1200000000) s.insert(k*2);
53 //                if(k*3<1200000000) s.insert(k*3);
54 //                if(k*5<1200000000) s.insert(k*5);
55 //                if(k*7<1200000000) s.insert(k*7);
56 //            }
57 
58             int l=1,r=len;
59             while(l<r)
60             {
61               int mid=(l+r)/2;
62               if (arr[mid]<x) l=mid+1;
63                 else r=mid;
64             }
65             printf("%d\n",arr[l]);
66 
67         }
68     }
69     return 0;
70 }

 

 

以上是关于2016 ACM/ICPC Asia Regional Qingdao Online 1001 I Count Two Three的主要内容,如果未能解决你的问题,请参考以下文章

2016 ACM/ICPC Asia Regional Shenyang Online

2016 ACM/ICPC Asia Regional Qingdao Online HDU5889

2016 ACM/ICPC Asia Regional Qingdao Online 1002 Cure

2016 ACM/ICPC Asia Regional Qingdao Online

2016 ACM/ICPC Asia Regional Qingdao Online HDU5883

2016 ACM/ICPC Asia Regional Shenyang Online