Uva 11971 Polygon 想法

多边形的组成条件是最长边不能占边长总和的一半,将木棒想象成圆多砍一刀,然后是简单概率.


Polygon

Time Limit: 1000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

Submit Status

Description

U   —
Polygon

Time Limit: 1 sec

Memory Limit: 32 MB

John has been given a segment of lenght N, however he needs a polygon. In order to create a polygon he has cut given segment K times at random positions (uniformly distributed cuts). Now he
has K+1 much shorter segments. What is the probability that he can assemble a polygon using all new segments?

INPUT

The number of tests T (T ≤ 1000) is given on the first line. T lines follow, each of them contains two integers N K (1 ≤ N ≤ 106; 1 ≤ K ≤
50) described above.

OUTPUT

For each test case output a single line "Case #T: F". Where T is the test case number (starting from 1) and F is the result as simple fraction in form of N/D.
Please refer to the sample output for clarity.

SAMPLE
INPUT

2
1 1
2 2

SAMPLE
OUTPUT

Case #1: 0/1
Case #2: 1/4

Problem by: Aleksej Viktorchik; Leonid Sislo

Huge Easy Contest #2

Source

Root :: AOAPC II: Beginning Algorithm Contests (Second Edition) (Rujia Liu) :: Chapter 10. Maths :: Examples

Root :: Prominent Problemsetters :: Leonid Shishlo

Root :: Prominent Problemsetters :: Aleksej Viktorchik

Root :: AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) :: Chapter 2. Mathematics :: Probability :: Exercises:
Intermediate

Submit Status

/* ***********************************************
Author        :CKboss
Created Time  :2015年01月30日 星期五 21时37分11秒
File Name     :UVA11971.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef long long int LL;
int n;

LL gcd(LL a,LL b)
{
	if(b!=0) return gcd(b,a%b);
	return a;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

	int T_T,cas=1;
	scanf("%d",&T_T);
	while(T_T--)
	{
		scanf("%*d%d",&n);
		LL fenzhi = (1LL<<n)-n-1;
		LL fenmu = (1LL<<n);
		LL g = gcd(fenzhi,fenmu);
		printf("Case #%d: %lld/%lld\n",cas++,fenzhi/g,fenmu/g);
	}

    return 0;
}
时间: 2024-08-08 09:38:42

Uva 11971 Polygon 想法的相关文章

UVA 11971 - Polygon(概率+几何概型)

UVA 11971 - Polygon 题目链接 题意:给一条长为n的线段,要选k个点,分成k + 1段,问这k + 1段能组成k + 1边形的概率 思路:对于n边形而言,n - 1条边的和要大于另外那条边,然后先考虑3边和4边形的情况,根据公式在坐标系中画出来的图,总面积为x,而不满足的面积被分成几块,每块面积为x/2k,然后在观察发现一共是k + 1块,所以符合的面积为x?x?(k+1)/2k,这样一来除以总面积就得到了概率1?(k+1)/2k 代码: #include <cstdio>

uva 11971 - Polygon(线性规划)

题目连接:uva 11971 - Polygon 题目大意:给定一个长度为N的线段,要求切K刀,分成K+1个线段,问能组成K+1边形的概率. 解题思路:K条线段能组成K边形的条件为任意一条边小于其他所有边的和,因为是求概率,所以和N无关. 根据高中线性规划的知识,以二维为例: 所以有ans=2K?K?12K #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typ

UVA 11971 - Polygon 数学概率

                                    Polygon  John has been given a segment of lenght N, however he needs a polygon. In order to create a polygonhe has cut given segment K times at random positions (uniformly distributed cuts). Now he has K + 1much sh

uva 11971 Polygon

https://vjudge.net/problem/UVA-11971 有一根长度为n的木条,随机选k个位置把它们切成k+1段小木条.求这些小木条能组成一个多边形的概率. 将木条看做一个圆,线上切k刀等价于圆上切k+1刀 如果能组成多边形,每一段木条的长度都要<圆周长/2 反过来,如果不能组成多边形,有且仅有一段长度>=圆周长/2 如图所示,第一刀可以随便切,接下来的每一刀都要在第一刀所在的那个半圆上 概率=(1/2)^k 每一个切点处,都可以断开成为线,共有k+1种断法 所以不能构成多边形

UVa 11971 Polygon (数学,转化)

题意:一根长度为n的木条,随机选k个位置将其切成k+1段,问这k+1段能组成k+1条边的多边形的概率. 析:这个题,很明显和 n 是没有任何关系的,因为无论 n 是多少那切多少段都可以,只与切多少段有关.然后我们要转化一下,不能直接做,因为不好做. 转化为一个圆上选 m+1 个点,能不能组成多边形,很容易知道如果一个边大于一半圆的周长,那就组不成多边形.然后位置是随便选的,概率就是1, 然后其他 m-1 个点,就只能放那一半上,每个都有1/2的概率,然后 m 个,就是1/(2^m),然后每个点都

UVa 11971 (概率) Polygon

题意: 有一根绳子,在上面随机选取k个切点,将其切成k+1段,求这些线段能够成k+1边形的概率. 分析: 要构成k+1边形,必须最长的线段小于其他k个线段之和才行. 紫书上给出了一种解法,但是感觉理解得不是太好,所以又去网上找了其他解法. 知乎上有人问过这个问题,而且给出了很多种严格的解法. 最后代码里将(1LL << i)写成(1 << i),这种细节应当注意. 1 #include <cstdio> 2 typedef long long ll; 3 4 ll gc

uva 11971

#include<bits/stdc++.h> using namespace std; typedef long long ull; ull gcd(ull a,ull b){ if(b == 0) return a; return gcd(b,a%b); } int main(){ ull t,n,k,cnt = 0,temp,a,b,c; cin >> t; while(t--){ cnt++; cin >> n >> k; // scanf(&quo

第10章例题(紫书)

21/21 题目都很基础,有很多题书上讲得比较详细,然后隔得时间有点久,所以具体什么trick都忘了,思路也懒得去回忆,所以将就着放上来了.... 例题10–1 Uva 11582 题意:输入a, b, n让你计算F[a^b]%n;其中这个F[i]是斐波那契数: 题解: 这题是快速幂+找循环节,用什么方法找循环节呢?因为第一个数是0和1,然后当再出现0和1的时候就是出现循环节的时候,然后假如找到了循环节T,然后就有F[n] = F[n % T],预处理找循环节,O(一百万左右),快速幂logn

UVA 12386 Smallest Polygon n个点的任意多边形求最小周长 科学的暴力

题目链接: 题意: 给定n个点,用n个点组成的多边形中(可以是凹多边形,但n个点一定要全在多边形上) 在所有能由n个点构成的多边形中 求最小面积的多边形的周长 - 最小周长. 思路: 首先我们选择一个定点,则接下来的数进行一个排列,有(n-1)!个排列. 这个序列相邻两个数之间有一条线段. 判断多边形合法:任意两条线段不相交即可.n^2 剩下就是简单的更新答案了. 所以复杂度是 ( n-1 ) ! * n*n #include <cstdio> #include <cstring>