UVa 651 - Deck

题目:在桌子边上罗扑克,使得扑克不掉下去,并且申处桌面最长,一直扑克数量求长度。

分析:简单题。第一个扑克一定摆在中间位置,长度是0.5;

每次,将前面的看成整体,下一个扑克当做上次的桌子,这样一定是最大,因为都在平衡边界;

整体i个扑克的重心在桌子的边沿位置即可,这时前i-1的整体重心一定在桌外,最后一重心在内;

因此,最后一个伸出桌面的距离一定是1/2*1/i(杠杆平衡,力与力臂的乘积是定值,杆长1/2)

结论,l = 1/2 + 1/4 + 1/6 + ... + 1/(2n)。

说明:想起刚进实验室时,在浙大做的新手任务了(⊙_⊙)。

#include <iostream>
#include <cstdlib>
#include <cstdio>

using namespace std;

int main()
{
	int n;
	printf("# Cards Overhang\n");
	while ( cin >> n ) {
		double l = 0.0;
		for ( int i = 1 ; i <= n ; ++ i )
			l += 0.5/i;
		printf("%5d%10.3lf\n",n,l);
	}
	return 0;
}

UVa 651 - Deck

时间: 2024-11-10 19:01:36

UVa 651 - Deck的相关文章

UVa 131 - The Psychic Poker Player

题目:手里有五张牌,桌上有一堆牌(五张),你可以弃掉手中的k张牌,然后从牌堆中取最上面的k个. 比较规则如下:(按优先级排序) 1.straight-flush:同花顺,牌面为T(10) - A,这里不论花色是否相同: 2.four-of-a-kind:四条,牌面有4个相同的值: 3.full-house:船牌,牌面有3个相同值,剩下2个也相同值: 4.flush:同花,五张牌的花色相同,不是同花顺: 5.straight:顺子,五张牌的值连续,A可以作为1也可以作为14: 6.three-of

uva 131 The Psychic Poker Player (暴力枚举)

uva 131 The Psychic Poker Player  The Psychic Poker Player  In 5-card draw poker, a player is dealt a hand of five cards (which may be looked at). The player may then discard between zero and five of his or her cards and have them replaced by the sam

UVA 10935 约瑟夫环

Throwing cards away I Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The following operation is per

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te

UVA 11014 - Make a Crystal(容斥原理)

UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, y, z)三点都为k的倍数的点的个数(要扣掉一个原点O).那么全部点就是f(1),之后要去除掉共线的,就是扣掉f(2), f(3), f(5)..f(n).n为素数.由于这些素数中包括了合数的情况,而且这些点必定与f(1)除去这些点以外的点共线,所以扣掉.可是扣掉后会扣掉一些反复的.比方f(6)在f

[UVa] Palindromes(401)

UVA - 401 Palindromes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDED

uva 401.Palindromes

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342 题目意思:给出一段字符串(大写字母+数字组成).判断是否为回文串 or 镜像串 or 回文镜像串 or 什么都不是.每个字母的镜像表格如下 Character Reverse Character Reverse Character Reverse A A M M Y Y B

[2016-02-19][UVA][129][Krypton Factor]

UVA - 129 Krypton Factor Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description You have been employed by the organisers of a Super Krypton Factor Contest in which contestants have very high mental and physica