zoukankan      html  css  js  c++  java
  • zoj 3665 数论 二分法 两个参数

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4888

    标题两个参数,途径:小参数的枚举,然后二分法大参数

    想想两个点。以后就不会了两个参数  然后在暴力,实上K能够非常大 所以时间不够

    自己写的二分枚举+高速幂程序WA了非常久。

    。。

    。没明确哪里错了  參考了别人的。。。

    //#pragma comment(linker, "/STACK:102400000,102400000")
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <iostream>
    #include <iomanip>
    #include <cmath>
    #include <map>
    #include <set>
    #include <queue>
    using namespace std;
    
    #define ls(rt) rt*2
    #define rs(rt) rt*2+1
    #define ll long long
    #define ull unsigned long long
    #define rep(i,s,e) for(int i=s;i<e;i++)
    #define repe(i,s,e) for(int i=s;i<=e;i++)
    #define CL(a,b) memset(a,b,sizeof(a))
    #define IN(s) freopen(s,"r",stdin)
    #define OUT(s) freopen(s,"w",stdout)
    const ll ll_INF = ((ull)(-1))>>1;
    const double EPS = 1e-8;
    const double pi = acos(-1.0);
    const int INF = 100000000;
    
    ll n,ansr,ansk;
    
    void test(ll d, ll up, int r)
    {
        ll sum;
        while(d<up)
        {
            ll mid=(d+up)/2;
            sum=0;
            ll know=1;//k^i
            int flag=0;
            for(int i=1;i<=r;i++)
            {
                know*=mid;
                sum+=know;
                if(sum>1000000000000LL || sum<0 )
                {
                    flag=1;
                    break;
                }
            }
            if(flag)
            {
                up=mid;
                continue;
            }
            if(sum>n)up=mid;
            else
                d=mid+1;
            if(sum+1 == n || sum==n)
            {
                if(mid*r < ansr*ansk)
                    ansr=r,ansk=mid;
                    break;
            }
        }
    }
    
    int main()
    {
        IN("zoj3665.txt");
        while(~scanf("%lld",&n))
        {
            ansr=1;
            ansk=n-1;//
            for(int i=2;i<=64;i++)
                test(1ll,1000000,i);
            printf("%lld %lld
    ",ansr,ansk);
        }
        return 0;
    }
    


    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    7、.net core 使用apollo
    6、初识Apollo
    5、supervisor安装使用
    Linux用户和用户组管理
    监督学习中的“生成模型”和“判别模型”
    Ubuntu 14.04 installation & bugs on Alienware-13
    Majority Element问题---Moore's voting算法
    redis之作为缓存的使用(二)
    redis之作为缓存的使用(五)缓存污染
    redis之作为缓存的使用(四)缓存击穿,雪崩,穿透
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4679499.html
Copyright © 2011-2022 走看看