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

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

 

进制转换。

现场根据题目给的两个公式,不断更新!!!

胡搞就可以了。

现场3A,我艹,一次循环开大TLE,一次开小WA,太逗了,呵呵

 

现场源码:

 

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <iostream>
 4 #include <algorithm>
 5 #include <queue>
 6 #include <map>
 7 #include <set>
 8 #include <vector>
 9 #include <string>
10 #include <math.h>
11 using namespace std;
12 int a[200];
13 int main()
14 {
15     //freopen("in.txt","r",stdin);
16     //freopen("out.txt","w",stdout);
17     int n;
18     while(scanf("%d",&n) == 1)
19     {
20         memset(a,0,sizeof(a));
21         a[100] = n;
22         for(int cc = 0;cc <= 100;cc++)
23         {
24             for(int i = 0;i <= 198;i++)
25                 if(a[i] > 0 && a[i+1] > 0)
26                 {
27                     int MM = min(a[i],a[i+1]);
28                     a[i] -= MM;
29                     a[i+1] -= MM;
30                     a[i+2] += MM;
31                 }
32             for(int i = 2;i <= 199;i++)
33                 if(a[i] >= 2)
34                 {
35                     int pp = a[i]/2;
36                     a[i] %= 2;
37                     a[i+1] += pp;
38                     a[i-2] += pp;
39                 }
40         }
41         int st = 100;
42         for(int i = 200;i >= 100;i--)
43             if(a[i] > 0)
44             {
45                 st = i;
46                 break;
47             }
48         int ed = 100;
49         for(int i = 0;i < 100;i++)
50             if(a[i] > 0)
51             {
52                 ed = i;
53                 break;
54             }
55         for(int i = st;i >= 100;i--)
56         {
57             printf("%d",a[i]);
58         }
59         if(ed < 100)printf(".");
60         for(int i = 99;i >= ed;i--)
61             printf("%d",a[i]);
62         printf("\n");
63     }
64     return 0;
65 }

 

 

 

    原文作者:算法小白
    原文地址: https://www.cnblogs.com/kuangbin/p/3506454.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞