2011阿里巴巴程序设计公开赛 / 1009 Board Game Dice
来源:互联网 发布:病理图像分析软件 编辑:程序博客网 时间:2024/06/10 16:42
这题一看就是算概率,把题意弄懂后,顺利推出公式,x*1/(n/mx) = mx*x/n.
因为精度wa了一次= =,然后输出少了空格PE了一次,额...
代码:
#include<cstdio>#include<cstring>#include<iostream>using namespace std;#define int64 long longint64 n, m, x;#define INF 21623int64 gcd(int64 a, int64 b){return b==0? a: gcd(b, a%b);}int64 getx(int64& mx){int64 ans = 1;int64 tn = n;int64 tm = m;while(tm<tn){//printf("%d*%d=%d\n", tm, tm*tm);if((int64)tm*tm>tn){tm*=m;ans+=1;}else if((int64)tm*tm<=tn){tm*=tm;ans*=2;}}mx = tm;return ans;}void solve(int64& a, int64& b){int64 mx;x = getx(mx);int64 d = gcd((int64)mx*x, (int64)n);a = (int64)mx*x/d;b = n/d;}int main(){int t;cin>>t;for(int i=1; i<=t; i++){cin>>n>>m;int64 a, b;solve(a, b);cout<<"Case "<<i<<": "<<a<<"/"<<b<<endl;}}
- 2011阿里巴巴程序设计公开赛 / 1009 Board Game Dice
- 阿里巴巴公开赛 HDU 3959 Board Game Dice(数学)
- 2011阿里巴巴程序设计公开赛 / 1001 Coin Game
- 2011阿里巴巴程序设计公开赛 1001 Coin Game
- 2011阿里巴巴程序设计公开赛 / 解题报告 8.18
- 2011阿里巴巴程序设计公开赛 / 1002 Fruit Ninja
- 2011阿里巴巴程序设计公开赛 总结(by胡浩)
- 2011阿里巴巴程序设计公开赛 / 1004 Level up
- HDU 3952 2011阿里巴巴程序设计公开赛
- HDU 3959 Board Game Dice
- nyoj 408 Board Game Dice
- 2011 阿里巴巴程序公开赛
- 2011百校联动“菜鸟杯”程序设计公开赛&&Flip Game
- NYOJ--408题Board Game Dice
- hdu - 3959 Board Game Dice(数学)
- 2011阿里巴巴程序设计公开赛 1003 I'll play a trick on you
- 2011阿里巴巴程序设计公开赛 / 1003 I'll play a trick on you
- 阿里巴巴2011公开赛1004 Level up HDU 3954 线段树
- poj 1101 The Game
- 多选图片一次上传(as+js) ,仿QQ相册
- 机器分配(machine.c/cpp/pas)
- magento,货币自动切换---根据IP
- 硬盘的分区
- 2011阿里巴巴程序设计公开赛 / 1009 Board Game Dice
- 坑爹的串口
- dojo初学 自己记的笔记
- c中for 循环里可以初始化变量吗
- ACMSTEP 3.1.3 母牛的故事 //递推
- Excel导入SqlServer数据库(一)
- 今天关注了一下电驴
- dojo笔记2
- 2011阿里巴巴程序设计公开赛 / 1001 Coin Game