HDU 4814 golden radio base small Simulation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.