I Count Two Three(打表+排序+二分查找)
Posted wsy107316
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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\n", *lower_bound(a, a+m, n)); 51 // cin>>n; 52 // cout<<*lower_bound(a,a+m,n)<<endl; 53 54 return 0; 55
以上是关于I Count Two Three(打表+排序+二分查找)的主要内容,如果未能解决你的问题,请参考以下文章
hdu5878 I Count Two Three(二分+ 打表)
HDU 5878 I Count Two Three (打表+二分查找) -2016 ICPC 青岛赛区网络赛
hdu 5878 I Count Two Three (2016 ACM/ICPC Asia Regional Qingdao Online 1001)
2016 ACM/ICPC Asia Regional Qingdao Online1001 &&hdoj 5878 I Count Two Three