UVA - 651

UVA - 651

题目介绍:
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?

大意:
放扑克,看到数据,猜测是1/2,1/4,1/6数列,试了下,过了。注意保留第三位小数的值要根据第四位来判断要不要+1.

AC代码:

#include<iostream>
using namespace std;

int main(){
	int n;
	printf("# Cards Overhang\n");
	while(scanf("%d",&n)==1){
		printf("%5d",n);
		double ans=0;
		for(int i=1;i<=n;i++){
			double temp=1.0;
			temp/=(2.0*i);
			ans+=temp;
		}
		int num=int(ans);
		ans-=num;
		printf("%6d.",num);
		ans*=1000;
		if(ans-int(ans)>=0.5)ans+=1;
		ans/=1000;
		for(int i=0;i<3;i++){
			ans*=10;
			cout<<int(ans);
			ans-=int(ans);
		}
		cout<<endl;
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值