Link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4814
The golden proportion cutting point is that a 10-digit number is now required to be converted into a phi-hexadecimal number, and there cannot be '11.
Idea: because two formulas are provided in the question, the question becomes a simple simulation question. Because the total number of Phi hexadecimal systems is only 200, and the data contains only 100 bits, the simulation starts from AA [50] = tot.
Code:
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<map>#include<cstdlib>#include<queue>#include<stack>#include<vector>#include<ctype.h>#include<algorithm>#include<string>#include <cstdlib>#define PI acos(-1.0)#define maxn 10005#define INF 0x7fffffffusing namespace std;int main(){ int aa[105]; int tot; while(~scanf("%d",&tot)) { memset(aa,0,sizeof(aa)); aa[50]=tot; while(1) { bool flag = 0 ; for(int i=0; i<=100; i++) { if(aa[i]>1) { flag = 1; aa[i+1]+=(aa[i]/2); aa[i-2]+=(aa[i]/2); aa[i]%=2; } } for(int i=0;i<=100;i++) { if(aa[i]>0&&aa[i+1]>0) { flag = 1; int t=min(aa[i],aa[i+1]); aa[i+2]+=t; aa[i+1]-=t; aa[i]-=t; } } if(flag==0) break; } int head,tail; for(int i=100;; i--) { if(aa[i]==1) { head=i; break; } } for(int i=0;; i++) { if(aa[i]==1) { tail=i; break; } } for(int i=head; i>=tail; i--) { if(i==49) printf("."); printf("%d",aa[i]); } printf("\n"); } return 0;}
HDU 4814 golden radio base small Simulation