zoukankan      html  css  js  c++  java
  • HDU 4814 Golden Radio Base 模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4814

    题目大意:

     把一个正整数表示为φ进制, φ = (1+√5)/2 。

    且已知:

    1. φ + 1 = φ 2 ,所以有11(φ) = 100(φ),且要求11要转变为100

    2. 2 * φ 2  = φ+ 1 。


    解题思路:

    观察发现,2 = 10.01。所以对于一个数N,能够从N/2 推导得到,是一个模拟的过程。我比赛的时候居然用了高速幂。。。


    代码:

    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<cmath>
    #include<ctime>
    #include<iostream>
    #include<algorithm>
    #include<string>
    #include<vector>
    #include<deque>
    #include<list>
    #include<set>
    #include<map>
    #include<stack>
    #include<queue>
    #include<numeric>
    #include<iomanip>
    #include<bitset>
    #include<sstream>
    #include<fstream>
    #define debug puts("-----")
    #define pi (acos(-1.0))
    #define eps (1e-8)
    #define inf (1<<30)
    #define LL long long
    using namespace std;
    int str[400];
    int tmp[400];
    int n;
    void out() {
            int st, ed;
            for (int i = 0; i < 400; i++) if (str[i]) {
                st = i;
                break;
            }
            for (int i = 399; i >= 0; i--) if (str[i]) {
                ed = i;
                break;
            }
            for (int i = st; i <= 200; i++) printf("%d", str[i]);
            if (ed > 200) {
                printf(".");
                for (int i = 201; i <= ed; i++) printf("%d", str[i]);
            }
            puts("");
    }
    void gao(int str[], int tmp[]) {
        for (int i = 0; i < 400; i++) str[i] += tmp[i];
        int k = 0;
        while(k < 400) {
            if (str[k] >= 2) {
                str[k - 1] += 1; str[k] -= 2; str[k + 2] += 1;
                k--;
            }
            else if (k > 0 && str[k] == 1 && str[k - 1] == 1) {
                str[k] = 0; str[k - 1] = 0; str[k - 2] += 1;
                k -= 2;
            }
            else k++;
        }
    }
    void fi_pow(int k) {
        memset(tmp, 0, sizeof(tmp)); memset(str, 0, sizeof(str));
        tmp[200] = 1;
        while(k) {
            if (k & 1) {
                gao(str, tmp);
                //out();
            }
            k >>= 1;
            gao(tmp, tmp);
        }
    }
    int main () {
        while(~scanf("%d", &n)) {
            if (n == 1) {
                puts("1");
                continue;
            }
            fi_pow(n);
            out();
        }
        return 0;
    }



  • 相关阅读:
    13点睛Spring4.1-Spring EL
    12点睛Spring4.1-Spring Aware
    11点睛Spring4.1-Property Editor
    10点睛Spring4.1-Application Event
    09点睛Spring4.1-AOP
    08点睛Spring4.1-Profile
    07点睛Spring4.1-BeanPostProcessor
    06点睛Spring4.1-Bean的初始化和销毁
    05点睛Spring4.1-国际化
    Solaris 11 配置IP地址
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/3965753.html
Copyright © 2011-2022 走看看