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

题目大意:

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

且已知:

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

2. 2 *
φ 2  = φ3 +
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;
}

HDU 4814 Golden Radio Base 模拟的更多相关文章

  1. HDU 4814 Golden Radio Base 小模拟

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4814 题意:黄金比例切割点是,如今要求把一个10进制的的数转化成一个phi进制的数,而且不能出现'11'的 ...

  2. hdu 4814 Golden Radio Base

    详解见:http://blog.csdn.net/tri_integral/article/details/18666797 #include<cstdio> #include<cs ...

  3. HDU 4818 Golden Radio Base (2013长春现场赛B题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4814 进制转换. 现场根据题目给的两个公式,不断更新!!! 胡搞就可以了. 现场3A,我艹,一次循环开 ...

  4. ACM学习历程——HDU4814 Golden Radio Base(数学递推) (12年成都区域赛)

    Description Golden ratio base (GRB) is a non-integer positional numeral system that uses the golden ...

  5. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  6. HDU 5948 Thickest Burger 【模拟】 (2016ACM/ICPC亚洲区沈阳站)

    Thickest Burger Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  7. HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))

    Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  8. HDU 5873 Football Games 【模拟】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  9. HDU 5504 GT and sequence 模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5504 思路:模拟 代码: #include<stdio.h>//------杭电5504 ...

随机推荐

  1. 如何捕获Wince下form程序的全局异常

    前言 上两篇文章我们总结了在winform程序下如何捕获全局的异常.那么同样的问题,在wince下我们如何来处理呢?用相同的代码来处理可以吗? 答案是否定的,上面的方案1完全不能解决wince下的情况 ...

  2. jQuery.localStorage() - jQuery SDK API

    jQuery.localStorage() - jQuery SDK API jQuery.localStorage() From jQuery SDK API   Jump to: navigati ...

  3. sql: sybase与oracle中insert into select和select into的用法

    1. sybase与oracle中insert into select和select into的用法 http://wjlvivid.iteye.com/blog/1921679 Sybase 一.首 ...

  4. Windows Azure入门教学系列 (二):部署第一个Web Role程序

    本文是Windows Azure入门教学的第二篇文章. 在第一篇教学中,我们已经创建了第一个Web Role程序.在这篇教学中,我们将学习如何把该Web Role程序部署到云端. 注意:您需要购买Wi ...

  5. 由于“Table(T_Test)”没有主键,因此无法在其上执行 Create、Update 或 Delete 操作

    在使用Linq To Sql查询的时候,遇到这么个问题,如图所示: 出现这个问题的原因就像途中所说的——没有主键(现在终于初步知道“为什么别人常说数据库中的逻辑主键是为了在编程中方便使用”的原因了,估 ...

  6. Python+Django+SAE系列教程15-----输出非HTML内容(图片/PDF)

    一个Django视图函数 必须 接受一个HttpRequest 实例作为它的第一个參数 返回一个HttpResponse 实例 从一个视图返回一个非HTML 内容的关键是在构造一个 HttpRespo ...

  7. 最近遇到VS2013,在打开解决方案时,报如下错误: 未找到与约束

    最近遇到VS2013,在打开解决方案时,报如下错误: “未找到与约束 ContractName Microsoft.Internal.VisualStudio.PlatformUI.ISolution ...

  8. ASP.NET从MVC5升级到MVC6

    1-1)文件结构的升级(Area和Filter知识总结) - ASP.NET从MVC5升级到MVC6   ASP.NET从MVC5升级到MVC6 总目录 MVC5项目结构 带有Areas和Filter ...

  9. qt宽字符串中文乱码(codec->toUnicode值得学习)

    乱码原因: QT使用的是utf-8 简体中文版的windows操作系统及其应用软件默认都是ANSI/GBK编码.而且这里应该是宽字符串. 多字节ANISGB 宽字符UNICODE 多字节显示标准字符的 ...

  10. tsunami:一种基于UDP协议的高速传输

    一. 需求 近期在做数据库迁移.常常须要打包实例传输.传统scp感觉非常慢. 二. 软件信息 1. 软件主页:http://tsunami-udp.sf.net/ 2. 软件安装:直接源代码make ...