大家好,又见面了,我是全栈君,祝每个程序员都可以多学几门语言。
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4814
题意:黄金比例切割点是
,如今要求把一个10进制的的数转化成一个phi进制的数,而且不能出现‘11’的情况。
思路:因为题目中给出了
两个式子,题目就变成了一道简单的模拟题了。因为整个phi进制的数最多仅仅有200,而数据中最多仅仅有100位,所以从aa[50]=tot 開始模拟就可以。
代码:
#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 0x7fffffff
using 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;
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/118430.html原文链接:https://javaforall.cn