zoukankan      html  css  js  c++  java
  • I Count Two Three(打表+排序+二分查找)

    I Count Two Three

    二分查找用lower_bound

    这道题用cin,cout会超时。。。

    AC代码;

     1 /* */
     2 # include <iostream>
     3 # include <cstring>
     4 # include <string>
     5 # include <cstdio>
     6 # include <cmath>
     7 # include <algorithm>
     8 using namespace std;
     9 
    10 const int TWO = 2;
    11 const int THREE = 3;
    12 const int FIVE = 5;
    13 const int SEVEN = 7;
    14 
    15 const long long MAXN = 1e9+100;
    16 const int N=1e6;
    17 long long a[N];
    18 int m;
    19 
    20 void maketable()
    21 {
    22     m=0;
    23     for(long long i=1; i<MAXN; i*=TWO )
    24     {
    25         for(long long j=1; j*i<MAXN; j*=THREE )
    26         {
    27             for(long long k=1; i*j*k<MAXN; k*=FIVE )
    28             {
    29                 for(long long l=1; i*j*k*l<MAXN; l*=SEVEN )
    30                 {
    31                     a[m++] = i*j*k*l;
    32                 }
    33             }
    34         }
    35     }
    36 }
    37 
    38 int main()
    39 {
    40     ios::sync_with_stdio(false);
    41     maketable();
    42     sort(a,a+m);
    43     int t;
    44     long long n;
    45     scanf("%d", &t);
    46     //cin>>t;
    47     while( t-- )
    48     {
    49         scanf("%lld",&n);
    50        printf("%lld
    ", *lower_bound(a, a+m, n));
    51 //        cin>>n;
    52 //        cout<<*lower_bound(a,a+m,n)<<endl;
    53     }
    54     return 0;
    55 }
  • 相关阅读:
    助教学期总结
    助教学习总结
    第十二周助教总结
    第十一周助教总结
    第十周助教总结
    第九周助教总结
    第八周助教总结
    第八周作业——基础
    19秋第三周助教总结
    助教学习总结
  • 原文地址:https://www.cnblogs.com/wsy107316/p/11462628.html
Copyright © 2011-2022 走看看