UVA 12585 Poker End Games 解题报告
2013-08-27 21:50
337 查看
比赛总结
题目
题意:
两个人玩扑克牌,A每局输赢的概率都是0.5.如果A有a张,B有b张,c=min(a,b),则该局获胜的人可从输的一方得到c张牌。谁先失去所有牌就输掉游戏。给出初始局面,求游戏进行的轮数的期望和A获胜的概率。
题解:
初看是概率DP,但是因为是个图所以不好写,然后又用高斯消元,但是某些局面某些矩阵元素会超过long long。测了几个自己的样例,发现获胜的概率就是a/(a+b),而进行的轮数直接搜索就可以:一个局面(a!=b)只有两个子局面,立刻结束或者继续,因为概率都是0.5,所以每搜一层就乘0.5,搜到25层以后已经对答案没什么影响了,可以直接忽略。
a、b的和为奇数时可以直接输出2。
题目
题意:
两个人玩扑克牌,A每局输赢的概率都是0.5.如果A有a张,B有b张,c=min(a,b),则该局获胜的人可从输的一方得到c张牌。谁先失去所有牌就输掉游戏。给出初始局面,求游戏进行的轮数的期望和A获胜的概率。
题解:
初看是概率DP,但是因为是个图所以不好写,然后又用高斯消元,但是某些局面某些矩阵元素会超过long long。测了几个自己的样例,发现获胜的概率就是a/(a+b),而进行的轮数直接搜索就可以:一个局面(a!=b)只有两个子局面,立刻结束或者继续,因为概率都是0.5,所以每搜一层就乘0.5,搜到25层以后已经对答案没什么影响了,可以直接忽略。
a、b的和为奇数时可以直接输出2。
//Time: //Length: #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <queue> using namespace std; #define MAXN 310 #define MP(x,y) make_pair(x,y) #define FI first #define SE second int a,b; int gcd(int a,int b) { while(a%b!=0) a%=b,swap(a,b); return b; } double dfs(int a,int b,int dep) { if(dep>25) return 0; if(a==0||b==0) return 0; int t=min(a,b); return (dfs(a-t,b+t,dep+1)+dfs(a+t,b-t,dep+1))*0.5+1; } int main() { //freopen("/home/moor/Code/input","r",stdin); int ncase,t; scanf("%d",&ncase); for(int hh=1;hh<=ncase;++hh) { scanf("%d%d",&a,&b); t=gcd(a,b); a/=t,b/=t; printf("Case %d: ",hh); printf("%.6f %.6f\n",(a+b)&1?2:dfs(a,b,1),a*1.0/(a+b)); } return 0; }
相关文章推荐
- UVa 12585 Poker End Games
- UVa 1153 Keep the Customer Satisfied 解题报告(贪心)
- Uva 1510 - Neon Sign 解题报告(计数)
- LeetCode 19. Remove Nth Node From End of List 解题报告
- UVAlive 6151 Beehives 解题报告
- [解题报告]《算法竞赛入门经典》基础题Volume 0. Getting Started Uva10055 Uva10071 Uva10300 Uva458 Uva494 Uva490 Uva445 Uva488 Uva489 Uva694 Uva457
- 第三章:UVa1588 解题报告
- (解题报告)Uva-1225 --- Digit Counting
- UVa 455 - Periodic Strings - ( C++ ) - 解题报告
- 【解题报告】uva103_Stacking Boxes(堆砌盒子, dp)
- UVALive 6582 Magical GCD (数学+数据结构) -- 解题报告
- UVa 10194 - Football (aka Soccer)解题报告
- UVa 540 Team Queue解题报告
- Uva12100Printer Queue NWERC2008 解题报告
- Uva 1315 - Crazy tea party 解题报告(找规律)
- Uva 10253 - Series-Parallel Networks 解题报告(递推)
- UVa 1316 Supermarket 解题报告(贪心)
- UVAlive 6160 Countdown 解题报告
- 第三章:UVa1586 解题报告
- URAL 1698||UVA 12009 解题报告