您的位置:首页 > 编程语言 > Go语言

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: