poj 1607 Deck(坑爹的水题啊)

简介:

Deck

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 745    Accepted Submission(s): 395


Problem Description
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
1 2 3 4 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
 

 

Source
采用打表法。
郁闷的是同样一个题,在hdu和zoj上边都通过了,在poj上边的输出略有不同,可是修改输出还是不行一直的wrong,因此这道题只是在zoj和hdu上边通过了。
hdu(1330)、zoj(1216)、poj(1607)同一个题,只是输出要求略有不同。可能是格式化的问题,不再追究了。
下边的代码是在zoj和hdu上通过的代码。
复制代码
#include <stdio.h>
#define MAX_NUM 100000

int main()
{
    int i;
    double num[MAX_NUM];
    double sum=0.0;
    int index;
    num[0] = 0.0;
    for(i=1;i<MAX_NUM;i++)
    {
        sum+=1.0/(i+i);
        num[i]=sum;
    }

    printf("# Cards  Overhang\n");
    while(scanf("%d",&index)!=EOF)
    printf("%5d%10.3lf\n",index,num[index]);
    return 0;
}
复制代码

 










本文转自NewPanderKing51CTO博客,原文链接:http://www.cnblogs.com/newpanderking/archive/2012/10/05/2712035.html ,如需转载请自行联系原作者



相关文章
|
Java C++
poj 1503 高精度加法
把输入的数加起来,输入0表示结束。 先看我Java代码,用BigINteger类很多东西都不需要考虑,比如前导0什么的,很方便。不过java效率低点,平均用时600ms,C/C++可以0ms过。
60 1
poj 1185 炮兵阵地 (状态压缩dp)
如果你是刚刚开始做状态压缩dp,我建议你先看看 poj 3254 Corn Fields 这是一道比这一题更简单,更容易入门的题目。 还有在代码中我用了一个很巧妙的方法求一个数二进制数中1的个数 具体请看我博客中 x& (x - 1)==0 这篇文章 链接 。
50 1
|
网络架构
POJ-1005,I Think I Need a Houseboat(数学题)
POJ-1005,I Think I Need a Houseboat(数学题)
POJ-2253,Frogger(最短路问题)
POJ-2253,Frogger(最短路问题)
HDOJ/HDU 2537 8球胜负(水题.简单的判断)
HDOJ/HDU 2537 8球胜负(水题.简单的判断)
119 0
HDOJ(HDU) 1465 不容易系列之一(错排)
HDOJ(HDU) 1465 不容易系列之一(错排)
94 0
poj-1012-约瑟夫问题
Description The Joseph's problem is notoriously known. For those who are not familiar with the original problem: from among n people, numbered 1, 2, .
816 0
【HDU 4451 Dressing】水题,组合数
有衣服、裤子、鞋数量分别为n,m,k,给出p对不和谐的衣-裤或裤-鞋搭配,问一共有多少种和谐的衣裤鞋的搭配。 全部的组合有Cn1Cm1Ck1种。 设p对中有p1对衣-裤,p2对裤-鞋,则不和谐的搭配共有p1*Ck1+p2*Cn1种,但有被重复计算两次的搭配共p3对,它们引用了同一裤。
918 0