ZOJ 1216 Deck

来源:互联网 发布:网络拓扑图在线制作 编辑:程序博客网 时间:2024/06/10 12:15
Deck

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Scenario

A single playing card can be placed on a table, carefully, so that the short edges of the card are parallel to the table's edge, and half the length of the card hangs over the edge of the table. If the card hung any further out, with its center of gravity off the table, it would fall off the table and flutter to the floor. The same reasoning applies if the card were placed on another card, rather than on a table. 

Two playing cards can be arranged, carefully, with short edges parallel to table edges, to extend 3/4 of a card length beyond the edge of the table. The top card hangs half a card length past the edge of the bottom card. The bottom card hangs with only 1/4 of its length past the table's edge. The center of gravity of the two cards combined lies just over the edge of the table.

Three playing cards can be arranged, with short edges parallel to table edges, and each card touching at most one other card, to extend 11/12 of a card length beyond the edge of the table. The top two cards extend 3/4 of a card length beyond the edge of the bottom card, and the bottom card extends only 1/6 over the table's edge; the center of gravity of the three cards lines over the edges of the table.

If you keep stacking cards so that the edges are aligned and every card has at most one card above it and one below it, how far out can 4 cards extend over the table's edge? Or 52 cards? Or 1000 cards? Or 99999?


Input

Input contains several nonnegative integers, one to a line. No integer exceeds 99999.


Output

The standard output will contain, on successful completion of the program, a heading: 

# Cards Overhang

(that's two spaces between the words) and, following, a line for each input integer giving the length of the longest overhang achievable with the given number of cards, measured in cardlengths, and rounded to the nearest thousandth. The length must be expressed with at least one digit before the decimal point and exactly three digits after it. The number of cards is right-justified in column 5, and the decimal points for the lengths lie in column 12.


Sample Input





30


Sample Output

The line of digits is intended to guide you in proper output alignment, and is not part of the output that your solution should produce. 

12345678901234567 
# Cards  Overhang 
    1     0.500 
    2     0.750 
    3     0.917 
    4     1.042 
   30     1.997


题意:就是计算1/2+1/4+...1/2n的和

代码:

#include <stdio.h>
int main()
{
    double deck[1000000];
    double sum=0;
    int n,j,k;
    for(j=1,k=2;j<1000000;j++,k+=2)
    {
        sum+=1.0/k;
        deck[j]=sum;
    }
    printf("# Cards  Overhang\n");
    while(scanf("%d",&n)!=EOF)
    {
        printf("%5d",n);
        printf("%10.3f\n",deck[n]);
    }
    return 0;
}


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 qq号一年没用了怎么办 微信里别人可以看到我手机号怎么办 用手机号注册的微信换号后怎么办 微信群推送名片很多人加怎么办 志高制冷显示ff怎么办 百度账号手机号换了怎么办 别人盗取手机号的通讯录该怎么办 58简历看不到真实号码怎么办 淘宝更换手机号码说已注册怎么办 系统把qq冻结了怎么办 qq被永久冻结好友怎么办 群发不小心发错怎么办 qq群成员满了怎么办 qq知道密码没手机号验证怎么办 改房本上的名字怎么办 支付宝租给别人怎么办 微信麻将房间卡怎么办 皮肤挤伤了发黑怎么办 指甲被挤了黑了怎么办 手指被挤了变黑怎么办 榆次买房太原户口怎么办 皮肤又红又黑怎么办 打仙桃晃晃老输怎么办 微信支付忘了摇怎么办 苹果手机微信摇一摇摇不了怎么办 打麻将牌背的时候怎么办 打麻将背的时候怎么办 同城游台球初使化失败怎么办 qq密码改忘了怎么办啊 qq头像显示不出来怎么办 qq的重要数据被清理怎么办 把qq数据删除了怎么办 手机qq头像显示不同怎么办 手机qq图片显示不出来怎么办 微信群聊右上角双人头像没了怎么办 支付宝好友没了怎么办 手机qq好友头像没了怎么办 微信语音变成听筒模式怎么办 微信语音为听筒模式怎么办 微信设置成听筒模式怎么办 微信验证看不全怎么办