2013 Asia Regional Changchun HDU - 4814 Golden Radio Base (进制模拟)

题意:将一个10进制的数转化为题目要求的进制

思路:按照题目给出的两个方程,分别将两式都乘以φ^(n-2)

得到: φ^(n-1)+φ^(n-2)=φ^n;2*φ^n=φ^(n+1)+φ^(n-2),剩下的就是跟着模拟了,

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <queue>
using namespace std;
const int maxn = 1000005;
#define inf 0x3f3f3f3f
#define maxn 2000100

int n;
int ans[110];

int main()
{
    int T;
    //scanf("%d",&T);
    while(scanf("%d",&n) != EOF)
    {
        memset(ans,0,sizeof(ans));
        int flag = 1;
        ans[51] = n;
        while(flag)
        {
            flag = 0;
            for(int i = 2; i < 100; i++)
                if(ans[i] > 1)
                {
                    ans[i+1] += ans[i] / 2;
                    ans[i-2] += ans[i] / 2;
                    ans[i] &= 1;
                    flag = 1;
                }
            for(int i = 2; i < 100; i++)
            {
                int t = min(ans[i-1],ans[i-2]);
                if(t > 0)
                {
                    ans[i] += t;
                    ans[i-1] -= t;
                    ans[i-2] -= t;
                    flag = 1;
                }
            }
        }
        int st = 100,ed = 0;
        while(!ans[st])
            st--;
        while(!ans[ed])
            ed++;
        for(int i = st; i >= ed; i--)
        {
            if(i == 50)
                printf(".");
            printf("%d",ans[i]);
        }
        printf("\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值