HDU 4814 Golden Radio Base(2013 ACM/ICPC 长春赛区现场赛)
来源:互联网 发布:怀化学院教务网络管理 编辑:程序博客网 时间:2024/06/05 23:44
Golden Radio Base
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1219 Accepted Submission(s): 494
Problem Description
Golden ratio base (GRB) is a non-integer positional numeral system that uses the golden ratio (the irrational number (1+√5)/2 ≈ 1.61803399 symbolized by the Greek letter φ) as its base. It is sometimes referred to as base-φ, golden mean base, phi-base, or, phi-nary.
Any non-negative real number can be represented as a base-φ numeral using only the digits 0 and 1, and avoiding the digit sequence "11" – this is called a standard form. A base-φ numeral that includes the digit sequence "11" can always be rewritten in standard form, using the algebraic properties of the base φ — most notably that φ + 1 = φ 2 . For instance, 11(φ) = 100(φ). Despite using an irrational number base, when using standard form, all on-negative integers have a unique representation as a terminating (finite) base-φ expansion. The set of numbers which possess a finite base-φ representation is the ring Z[1 + √5/2]; it plays the same role in this numeral systems as dyadic rationals play in binary numbers, providing a possibility to multiply.
Other numbers have standard representations in base-φ, with rational numbers having recurring representations. These representations are unique, except that numbers (mentioned above) with a terminating expansion also have a non-terminating expansion, as they do in base-10; for example, 1=0.99999….
Coach MMM, an Computer Science Professor who is also addicted to Mathematics, is extremely interested in GRB and now ask you for help to write a converter which, given an integer N in base-10, outputs its corresponding form in base-φ.
Any non-negative real number can be represented as a base-φ numeral using only the digits 0 and 1, and avoiding the digit sequence "11" – this is called a standard form. A base-φ numeral that includes the digit sequence "11" can always be rewritten in standard form, using the algebraic properties of the base φ — most notably that φ + 1 = φ 2 . For instance, 11(φ) = 100(φ). Despite using an irrational number base, when using standard form, all on-negative integers have a unique representation as a terminating (finite) base-φ expansion. The set of numbers which possess a finite base-φ representation is the ring Z[1 + √5/2]; it plays the same role in this numeral systems as dyadic rationals play in binary numbers, providing a possibility to multiply.
Other numbers have standard representations in base-φ, with rational numbers having recurring representations. These representations are unique, except that numbers (mentioned above) with a terminating expansion also have a non-terminating expansion, as they do in base-10; for example, 1=0.99999….
Coach MMM, an Computer Science Professor who is also addicted to Mathematics, is extremely interested in GRB and now ask you for help to write a converter which, given an integer N in base-10, outputs its corresponding form in base-φ.
Input
There are multiple test cases. Each line of the input consists of one positive integer which is not larger than 10^9. The number of test cases is less than 10000. Input is terminated by end-of-file.
Output
For each test case, output the required answer in a single line. Note that trailing 0s after the decimal point should be wiped. Please see the samples for more details.
Sample Input
123610
Sample Output
110.01100.011010.000110100.0101Hint
Source
2013 Asia Regional Changchun
Recommend
liuyiding
题意:
给你一个数字让你把他转化成无理数进制的形式并且只用01表示(同时不能出现相邻数字都是1)
思路:
这一题其他大佬的博客我第一眼直接看不懂,后来自己悟出来了,决定自己写清楚。
首先我的第一感觉就是这题的结果不是最终那个数,但是显然不是的。比如这题的10.01为什么是2很好懂的,按照进制转换的规则,是不是φ+φ^-2,这里这个数就是等于2。我们将数组的第50个元素首先设置为n,然后向两边扩散。
代码:
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<iostream>#include<queue>using namespace std;const int MAXN = 205;int main(){ int a[MAXN],n,bas=100,flag; while(scanf("%d",&n)!=EOF) { memset(a,0,sizeof(a)); a[50] = n,flag = 1; while(flag) { flag = 0; for(int i = 2; i < 100; i++) if(a[i]>1) { a[i-2]+=a[i]/2; a[i+1]+=a[i]/2; a[i]%=2; flag = 1; } for(int i = 0; i<100;i++) if(a[i]&&a[i+1]) { int tmp = min(a[i],a[i+1]); a[i+2]+=tmp; a[i]-=tmp; a[i+1]-=tmp; flag = 1; } } int st,ed; for(int i = 100; i >= 0; i--) if(a[i]){st = i;break;} for(int i = 0; i < 100; i++) if(a[i]){ed = i;break;} for(int i = st; i >= ed; i--) { if(i==49) printf("."); printf("%d",a[i]); } printf("\n"); } return 0;}
阅读全文
0 0
- HDU 4814 Golden Radio Base(2013 ACM/ICPC 长春赛区现场赛)
- 2013ICPC长春 HDU 4814 Golden Radio Base 乱搞
- HDU - 4814 Golden Radio Base (长春赛区B题)
- HDU 5534 HDU 5532 2015ACM-ICPC长春赛区现场赛H题
- HDU 5532 2015ACM-ICPC长春赛区现场赛F题
- HDU 5533 2015ACM-ICPC长春赛区现场赛G题
- HDU 5536 2015ACM-ICPC长春赛区现场赛J题
- HDU 5538 2015ACM-ICPC长春赛区现场赛L题
- HDU 4814 Golden Radio Base
- HDU 4814 Golden Radio Base
- HDU 4814 Golden Radio Base
- HDU 4814 Golden Radio Base
- HDU 4814 Golden Radio Base
- HDU 4814 Golden Radio Base
- HDU 5117 Fluorescent(2014 ACM/ICPC 北京赛区现场赛)
- 2012年ACM/ICPC长春赛区现场赛题解:Alice and Bob
- 2012年ACM/ICPC长春赛区现场赛题解:Bit Magic
- 2013 ACM/ICPC 亚洲区域赛长春赛区 总结
- 10.使用autotools自动生成Makefile
- Docker入门系列(一):目标和安排
- git操作
- 图解SQL的inner join、left join、right join、full outer join、union、union all的区别
- 判断一棵二叉树,是否是搜索二叉树
- HDU 4814 Golden Radio Base(2013 ACM/ICPC 长春赛区现场赛)
- 【SQL Server学习笔记】22:集合运算/多集运算(含ALL替代方案)
- 【项目实战】---SVN遇到问题---Error:Unable to connect to a repository at URL'……'
- char [] 和char * 之间有什么区别?
- sublime学习笔记(1).解决中文输入问题
- 【LeetCode】C# 63、Unique Paths II
- leetcode3. Longest Substring Without Repeating Characters
- 富人永远在坚持的5个铁律!
- 如何去掉input默认样式