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 }
  • 相关阅读:
    微支付开发(.net)
    微信公众平台开发(一) 配置接口
    [040] 微信公众帐号开发教程第16篇-应用实例之历史上的今天
    [039] 微信公众帐号开发教程第15篇-自定义菜单的view类型(访问网页)
    [038] 微信公众帐号开发教程第14篇-自定义菜单的创建及菜单事件响应
    [037] 微信公众帐号开发教程第13篇-图文消息全攻略
    【微网站开发】之微信内置浏览器API使用
    .Net(c#)汉字和Unicode编码互相转换
    jquery.uploadify上传文件配置详解(asp.net mvc)
    微信公众平台入门开发教程.Net(C#)框架
  • 原文地址:https://www.cnblogs.com/Annetree/p/5879928.html
Copyright © 2011-2022 走看看