zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 22 B. The Golden Age(暴力)

    题目链接:http://codeforces.com/contest/813/problem/B

    题意:就是有一个数叫做不幸运数,满足题目的 n = x^a + y^b,现在给你一个区间[l,r],让你找一个在这个区间里面一个最长的区间使得这个区间里面的所有数都不是不幸运数,让你输出最长区间的区间长度 。

    先用两个数组将x的n次方和y的n次方存起来,然后暴力枚举,用map将符合的条件的数存起来,不幸运数的区间就是两个幸运数的位置之差相减再减1。(注意map迭代器的用法)

    #include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pi acos(-1)
    const int INF = 0x3f3f3f3f;
    const ll N=1e18;
    map<ll,ll>ma;
    ll x[110],y[110];
    
    int  main()
    {
        memset(x,0,sizeof(x));
        memset(y,0,sizeof(y));
        ll a,b,l,r;
        scanf("%I64d%I64d%I64d%I64d",&a,&b,&l,&r);
        x[0]=1;
        y[0]=1;
        ma[l-1]=1;
        ma[r+1]=1;
        for(int i=1; x[i-1]<=N/a; i++)
            x[i]=x[i-1]*a;
        for(int i=1; y[i-1]<=N/b; i++)
            y[i]=y[i-1]*b;
        for(int i=0; x[i]!=0; i++)
            for(int j=0; y[j]!=0; j++)
                if(x[i]+y[j]<=r&&x[i]+y[j]>=l)
                    ma[x[i]+y[j]]=1;
        map<ll,ll>::iterator fir,sec;
        sec=ma.begin();
        fir=ma.begin();
        sec++;
        ll ans=0;
        for(; sec!=ma.end(); fir++,sec++)
            ans=max(ans,sec->first-fir->first-1);
        printf("%I64d",ans);
        return 0;
    }
  • 相关阅读:
    org.json.JSONObject的optXXX方法
    android Fragment的数据传递
    android .9图片的制作
    android handler
    CSS中的!important属性用法
    JS中的prototype
    JavaScript 函数创建思想
    css笔记
    Frameset使用教程
    HDU 5536 Chip Factory 【01字典树删除】
  • 原文地址:https://www.cnblogs.com/scaulok/p/7026907.html
Copyright © 2011-2022 走看看