码迷,mamicode.com
首页 > 其他好文 > 详细

Uva 11971 Polygon 想法

时间:2015-01-30 22:40:26      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:


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



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

 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

 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;
}




Uva 11971 Polygon 想法

标签:

原文地址:http://blog.csdn.net/ck_boss/article/details/43316495

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!