UVA 11971 Polygon
2015-01-27 17:53
162 查看
U — Polygon
Time Limit: 1 secMemory 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 testsT(T ≤ 1000) is given on the first line.
Tlines 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
Tis the test case number (starting from 1) and
Fis 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
思路:首先题目里面给的N是没有意义的...我们假设线段总长度是1.其次我们要知道假设多边形的K+1条边的长度分别为x1<=x2<=x3.....xk+1, 那么则有x1+x2+x3+...+xk>xk-1,即x1+x2+....+xk > 0.5。根据这个方程不好算,我们算它的反面,也就是说有且仅有一条边的长度不小于0.5。
于是:
推导过程就自己来吧....有规律的
代码:
#include <iostream> #include <string.h> #include <cstdio> #include <cstring> #include <cassert> #include <queue> #include <vector> #include <map> #include <set> #include <cmath> #include <algorithm> using namespace std; #define rep(i,a,b) for(int i=(a);i<(int)(b);++i) #define rrep(i,b,a) for(int i=(b);i>=(int)(a);--i) #define clr(a,x) memset(a,x,sizeof(a)) #define ll long long #define eps 1e-13 int main() { #ifdef ACM freopen("in.txt","r",stdin); #endif int T; cin >> T; rep(cas,1,T+1) { int N, K; scanf("%d%d",&N,&K); printf("Case #%d: ",cas); if (K == 1) puts("0/1"); else { ll fenzi = (K+1); ll fenmu = 1LL << K; fenzi = fenmu - fenzi; ll g = __gcd(fenzi,fenmu); fenzi /= g; fenmu /= g; printf("%lld/%lld\n",fenzi,fenmu); } } }
相关文章推荐
- UVA 11971(p335)----Polygon
- uva 11971 Polygon
- UVa11971 - Polygon(连续概率)
- uva11971 Polygon
- UVA 11971 Polygon——连续概率
- UVa11971 Polygon
- uva 11971 Polygon
- Uva 11971 Polygon 想法
- UVA11971 - Polygon
- Polygon UVA - 11971
- uva 11971 - Polygon(连续概率问题)
- Uva 11971 Polygon(数论、概率)
- UVa 11971 - Polygon(概率)
- UVA 11971 Polygon 多边形(连续概率)
- UVA 11971 - Polygon(概率+几何概型)
- 线性规划·UVA-11971·Polygon
- uva 11971 Polygon 连续概率
- UVA 11971 - Polygon
- UVA - 11971 Polygon
- UVA11971 - Polygon