zoukankan      html  css  js  c++  java
  • UVa11549计算器谜题[floyd判圈]

    题意:

    有个老式计算器,每次只能记住一个数字的前n位。现在输入一个整数k,然后反复平方,一直做下去,能得到的最大数是多少。例如,n=1,k=6,那么一次显示:6,3,9,1...


    白书上的题

    set,hash都占空间也不快

    裸floyd判圈

    洛谷U4984

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    using namespace std;
    typedef long long ll;
    const int N=11;
    inline ll read(){
        char c=getchar();ll x=0,f=1;
        while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        return x;
    }
    ll n,k;
    int buf[N];
    int nxt(int n,ll k){
        if(!k) return 0;
        ll tmp=(ll)k*k;
        int L=0;
        while(tmp>0) {buf[L++]=tmp%10;tmp/=10;}
        if(n>L) n=L;
        int ans=0;
        for(int i=0;i<n;i++) ans=ans*10+buf[--L];
        return ans;
    }
    int main(){
        n=read();k=read();
        int k1=k,k2=k,ans=k;
        do{
            k1=nxt(n,k1);
            k2=nxt(n,k2); ans=max(ans,k2);
            k2=nxt(n,k2); ans=max(ans,k2);
        }while(k1!=k2);
        cout<<ans;
    }
  • 相关阅读:
    配置文件配置网络
    安装Linux centos 7.3
    java二维字符数组的输入
    前端保存JSON文件到本地
    在Springboot中使用swagger2
    Vue better-scroll使用指南
    解决端口占用问题
    CheckSum(校验和)计算
    区分按字寻址与按字节寻址
    进制转换
  • 原文地址:https://www.cnblogs.com/candy99/p/5925247.html
Copyright © 2011-2022 走看看