Zoj 3665 Binary Number Two Parameters

Source: Internet
Author: User

Http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemid = 4888

The problem of two parameters. Solution: enumerate the smaller parameter, and then the second parameter.

Think of binary, then the two parameters will not be and then the brute force, but in fact K can be very large, so time is not enough

Self-written binary enumeration + fast power program wa for a long time .... I don't understand what's wrong with someone else's reference...

//#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\n",ansr,ansk);    }    return 0;}


Zoj 3665 Binary Number Two Parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.