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;
    }
  • 相关阅读:
    小程序 筛选
    Travel 项目环境配置
    ajax
    vue 项目编译打包
    自学网
    使用npm打包vue项目
    vue音乐播放器项目 二级路由跳转
    better-scroll (下拉刷新、上拉加载)
    Linux命令
    hibernate存储过程 3
  • 原文地址:https://www.cnblogs.com/candy99/p/5925247.html
Copyright © 2011-2022 走看看