首页 > 代码库 > 2016 ACM/ICPC Asia Regional Qingdao Online HDU5878

2016 ACM/ICPC Asia Regional Qingdao Online HDU5878

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5878

解法:先保存,再二分查询~具体http://blog.csdn.net/coder_xia/article/details/6707600

#include<stdio.h>//#include<bits/stdc++.h>#include<string.h>#include<iostream>#include<math.h>#include<sstream>#include<set>#include<queue>#include<map>#include<vector>#include<algorithm>#include<limits.h>#define MAXN (100000+10)#define MAXM (100000)#define inf 0x3fffffff#define INF 0x3f3f3f3f#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define LL long long#define ULL unsigned long longusing namespace std;long long data[10000];long long index = 0;void get(int n){    data[0] = 1;    long long T2 = 0;    long long T3 = 0;    long long T5 = 0;    long long T7 = 0;   // long long index = 0;    while (index < n)    {        index++;        long long d1=min(data[T2] * 2, data[T3] * 3);        long long d2=min(data[T5] * 5, data[T7] * 7);        long long d = min(d1,d2);        data[index] = d;        while (data[T2] * 2 == data[index]) T2++;        while (data[T3] * 3 == data[index]) T3++;        while (data[T5] * 5 == data[index]) T5++;        while (data[T7] * 7 == data[index]) T7++;    }}int main(){    int i,n;    get(7000);   // cout<<data[7000]<<endl; //  cout<<index<<endl;    int t;    while(~scanf("%d",&t))    {    }    while(t--)    {        int m;        scanf("%d",&m);        int pos=lower_bound(data,data+index,m)-data;        printf("%lld\n",data[pos]);    }    return 0;}

  

2016 ACM/ICPC Asia Regional Qingdao Online HDU5878