zoukankan      html  css  js  c++  java
  • 2018 CCPC 女生赛 hdoj6288 缺失的数据范围

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6288

    Summarize:
    1、二分查找答案;

    2、自带log函数精度不够,需自己写;

    3、注意二分递归的左右区间;

    4、计算中可能爆LL,故需尽可能做一步就判断一次;

     

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 using namespace std;
     5 #define LL long long
     6 
     7 LL T, a, b, k;
     8 LL R = 1e18;
     9 
    10 LL log2(LL n)
    11 {
    12     for(int i=0; i<=64; i++)
    13         if((LL)pow(2LL, i) >= n)
    14             return i;
    15 }
    16 
    17 bool judge(LL n)
    18 {
    19     LL x = n;
    20     for(int i=1; i<a; i++) {
    21         if(x > k/n) return false;
    22         x *= n;
    23     }
    24     
    25     LL t = log2(n);
    26     LL y = t;
    27     for(int i=1; i<b; i++) {
    28         if(y>k || x>k/y) return false;
    29         y *= t;
    30     }
    31 //    cout<<"x,y:    "<<x<<' '<<y<<endl;
    32     
    33     if(x > k/y)
    34         return false;
    35     return true;
    36 }
    37 
    38 void half_find(LL l, LL r)
    39 {
    40     if(l == r) {
    41         printf("%lld
    ", l);
    42         return;
    43     }
    44     LL mid = (l+r)/2+1LL;
    45 //    cout<<"AA "<<l<<' '<<r<<' '<<mid<<endl;
    46     if(judge(mid))
    47         half_find(mid, r);
    48     else
    49         half_find(l, mid-1);
    50 }
    51 
    52 int main()
    53 {
    54     ios::sync_with_stdio(false);
    55     scanf("%lld", &T);
    56     while(T--)
    57     {
    58         scanf("%lld%lld%lld", &a, &b, &k);
    59         half_find(1, R);
    60     }
    61     
    62     return 0;
    63 }
  • 相关阅读:
    NSUserDefaults存储自定义类
    beginBackgroundTaskWithExpirationHandle
    instancetype
    #define const extern
    singleton
    报错:说改变了系统文件。解决方法
    不合法语句 self.contentView.frame.origin.x = x;
    google应用商店的解决
    笔记
    读流testDemo
  • 原文地址:https://www.cnblogs.com/liubilan/p/10933424.html
Copyright © 2011-2022 走看看