zoukankan      html  css  js  c++  java
  • 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
    ",arr[len]);
    35     //for(int i=1;i<=len;i++) printf("%d ",arr[i]);
    36    // printf("%d
    ",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
    ",*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
    ",arr[l]);
    66 
    67         }
    68     }
    69     return 0;
    70 }
  • 相关阅读:
    网络协议(一)HTTP请求报文(请求行、请求头、请求体),响应报文
    Java集合(五) Set 添加元素
    Java 泛型面试题
    并发编程-线程池(二)线程池回收线程
    Java(二)equal 和 hashcode使用
    Java 泛型(一)作用和使用
    Java排序(一)实现类的排序
    Java排序(二)排序算法的稳定性
    SDL 程序编译错误-undefined reference to `SDL_GetError'
    SDL程序编译错误-error: conflicting types for ‘_XData32’
  • 原文地址:https://www.cnblogs.com/Annetree/p/5879928.html
Copyright © 2011-2022 走看看