Polygon UVA - 11971
2017-11-10 15:16
405 查看
按照先解对立事件的方法进行求解。将问题抽象到一个圆周上,如果出现了从某个点开始到另外一个截取点至少横跨了半个圆周,同时在这半个圆周内没有其他的截取点,那么这种截取方式肯定会失败,所以依次求解出所有的这种情况下的概率,该情况的对立也就是合法的情况,具体实现见如下代码:
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<deque>
#include<functional>
using namespace std;
typedef long long LL;
LL gcd(LL a,LL b){
if (!b) return a;
return gcd(b, a%b);
}
int main(){
int T;
cin >> T;
for (int i = 1; i <= T; i++){
int N, K;
cin >> N >> K;
LL a, b;
b = 1LL << K;
a = b - K - 1;
LL t = gcd(a,b);
a /= t;
b /= t;
cout << "Case #" << i << ": " << a << "/" << b << endl;
}
return 0;
}
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<deque>
#include<functional>
using namespace std;
typedef long long LL;
LL gcd(LL a,LL b){
if (!b) return a;
return gcd(b, a%b);
}
int main(){
int T;
cin >> T;
for (int i = 1; i <= T; i++){
int N, K;
cin >> N >> K;
LL a, b;
b = 1LL << K;
a = b - K - 1;
LL t = gcd(a,b);
a /= t;
b /= t;
cout << "Case #" << i << ": " << a << "/" << b << endl;
}
return 0;
}
相关文章推荐
- uva 11971 - Polygon(线性规划)
- UVA 11971 Polygon
- UVa 11971 (概率) Polygon
- UVa11971 - Polygon(连续概率)
- uva 11971 Polygon 连续概率
- Uva 11971 Polygon(数论、概率)
- 线性规划·UVA-11971·Polygon
- UVa11971 Polygon
- UVA - 11971 Polygon
- Uva 11971 Polygon 想法
- UVa 11971 Polygon
- UVa 11971 - Polygon(概率)
- UVA 11971 Polygon 多边形(连续概率)
- UVa 11971 Polygon (数学,转化)
- uva 11971 Polygon
- uva11971 Polygon
- UVA 11971(p335)----Polygon
- uva 11971 - Polygon(连续概率问题)
- UVA11971 - Polygon
- UVA11971 - Polygon