设为首页 加入收藏

TOP

hdu 1330(Deck)(递推)(读题太费劲)
2015-07-20 17:25:31 来源: 作者: 【 】 浏览:3
Tags:hdu 1330 Deck 递推 费劲

Deck

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

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 South Central USA 1998 题意: 就是在桌面上铺纸牌,求最多能够超过桌面多少。 递推之后的公式为: a[n]=a[n-1]×1.0/2/n;(因为是小数所以要乘以1.0,) 代码如下:
#include
  
   
int main()
{
	int i,n;
	double a[100000];//double型,最后精确到小数点之后的三位 
	a[1]=0.5;//第一张纸牌最多超过百分之五十 
	for(i=1;i<100000;i++)//递推公式 
	a[i]=a[i-1]+1.0/2/i;
	printf("# Cards  Overhang\n");
	while(~scanf("%d",&n))
	{
		printf("%5d%10.3lf\n",n,a[n]);//要精确到小数点后三位。。。 
	} 
	return 0;
}
  


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇穷举递归和回溯算法终结篇 下一篇UVA1492 - Adding New Machine(扫..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·微服务 Spring Boot (2025-12-26 18:20:10)
·如何调整 Redis 内存 (2025-12-26 18:20:07)
·MySQL 数据类型:从 (2025-12-26 18:20:03)
·Linux Shell脚本教程 (2025-12-26 17:51:10)
·Qt教程,Qt5编程入门 (2025-12-26 17:51:07)