Chieh's Blog

Because Of Coding

ZOJ Problem Set - 3665 Yukari's Birthday

Chieh posted @ 2015年1月05日 16:03 in ZOJ , 389 阅读

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

分析:起先想要把所有可能求出来。。。然后二分答案。。。但是内存不够呀然后各种优化啊。。。还是不行啊。。。果然是彩笔~接着就想着暴力。。。暴力你妹啊!!!各种TLE啊~~~没办法了。。想着在线二分。。。但是二分k还是r呢。。。第一直觉是k。。然后就往k里面想了。。。发现k无法正常二分。。。必需要有什么东西可以限制k的大小就可以二分。。。想想r不是很小么40...那就用r来限制k二分。。。接着就是各种悲剧渣死了。。。各种Wa。。。后来看了别人的题解。。。发现我二分里面有些是多余的。。。果然是自己贱啊但是想法还是正确的。。最后改了几个地方就AC了

/*
Author:Chieh
Grow up happy
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#define LL long long
using namespace std;
LL n;
LL cal(int e)
{
    LL l=2,r=min(n,1000000LL);
    while(l<=r)
    {
        LL mid=(l+r)/2;
        LL over=1;
        LL tm=1;
        for(int i=1; i<=e; i++)
        {
            tm=tm*mid;
            over+=tm;
            if(over>n+1)break;
        }
        if(over==n+1||over==n)return mid;
        if(over>n+1)r=mid-1;
        else
        {
            l=mid+1;
        }
    }
    return 0;
}
void play()
{
    LL a=1,b=n-1;
    for(int i=2; i<=39; i++)
    {
        LL t=cal(i);
        if(t==0)continue;
        if(t*i<a*b)
        {
            a=i;
            b=t;
        }
        else if(t*i==a*b)
        {
            if(a>i)
            {
                a=i;
                b=t;
            }
        }
    }
    printf("%lld %lld\n",a,b);
}
int main()
{

    while(scanf("%lld",&n)!=EOF)
    {
        play();
    }
    return 0;
}

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter