HDU5978 To begin or not to begin(概率+规律)
来源:互联网 发布:软件权限管理 编辑:程序博客网 时间:2024/05/16 15:40
To begin or not to begin
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 783 Accepted Submission(s): 508
Problem Description
A box contains black balls and a single red ball. Alice and Bob draw balls from this box without replacement, alternating after each draws until the red ball is drawn. The game is won by the player who happens to draw the single red ball. Bob is a gentleman and offers Alice the choice of whether she wants to start or not. Alice has a hunch that she might be better off if she starts; after all, she might succeed in the first draw. On the other hand, if her first draw yields a black ball, then Bob’s chances to draw the red ball in his first draw are increased, because then one black ball is already removed from the box. How should Alice decide in order to maximize her probability of winning? Help Alice with decision.
Input
Multiple test cases (number of test cases≤50), process till end of input.
For each case, a positive integer k (1≤k≤10^5) is given on a single line.
For each case, a positive integer k (1≤k≤10^5) is given on a single line.
Output
For each case, output:
1, if the player who starts drawing has an advantage
2, if the player who starts drawing has a disadvantage
0, if Alice's and Bob's chances are equal, no matter who starts drawing
on a single line.
1, if the player who starts drawing has an advantage
2, if the player who starts drawing has a disadvantage
0, if Alice's and Bob's chances are equal, no matter who starts drawing
on a single line.
Sample Input
12
Sample Output
01
Source
2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学)
Recommend
wange2014 | We have carefully selected several similar problems for you: 6022 6021 6020 6019 6018
解题思路:
【题意】
箱子里有1个红球和k个黑球
Alice和Bob轮流不放回地从箱子里随机取出一个球
当某人取到红球时获得胜利,游戏结束
问先手是否获胜几率更大,几率更大,输出"1";几率更小,输出"2";几率相等,输出"0"
【类型】
概率水题
【分析】
此题关键还是要多尝试,手动计算一下
当k=1时,一个红球和一个黑球,先手获胜的概率P为
当k=2时,一个红球和两个黑球,先手获胜的概率P为
当k=3时,一个红球和三个黑球,先手获胜的概率P为
故,当k时,先手获胜的概率P为
那我只需判断两者大小关系即可
【时间复杂度&&优化】
O(1)
网上的比较正统的方式
/*Sherlock and Watson and Adler*/#pragma comment(linker, "/STACK:1024000000,1024000000")#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<stack>#include<math.h>#include<vector>#include<map>#include<set>#include<list>#include<bitset>#include<cmath>#include<complex>#include<string>#include<algorithm>#include<iostream>#define eps 1e-9#define LL long long#define PI acos(-1.0)#define bitnum(a) __builtin_popcount(a)using namespace std;const int N = 5005;const int M = 100005;const int inf = 1000000007;const int mod = 1000000007;const int MAXN = 100005;int main(){ int k,p; while(~scanf("%d",&k)) { p=k/2+1; if(p>k+1-p) puts("1"); else if(p<k+1-p) puts("2"); else puts("0"); } return 0;}
但是AC代码:
#include<bits/stdc++.h>using namespace std;int main(){ int k; while(~scanf("%d", &k)){ if(k%2) printf("0\n"); else printf("1\n"); } return 0;}
0 0
- HDU5978 To begin or not to begin(概率+规律)
- HDU 5978 To begin or not to begin(概率)
- HDU 5978 To begin or not to begin(概率)
- HDU 5978 To begin or not to begin (简单博弈--找规律)
- HDU 5978 To begin or not to begin (概率数学)
- hdu 5978 To begin or not to begin(概率期望)
- HDU5971 To begin or not to begin
- HDU 5978 To begin or not to begin(水题)
- hdu 5978 · To begin or not to begin【概率题】【手速题】
- HDU 5978 icpc 大连 To begin or not to begin
- hdu 5978 To begin or not to begin
- ICPC 2016 DALIAN H To begin or not to begin
- hdoj 5978 To begin or not to begin
- hdu 5978 To begin or not to begin
- HDU 5978 && 2016ICPC大连 H: To begin or not to begin
- To Begin
- perl---use lib or BEGIN{ } to add directory to @INC
- Begin to sell
- poj 2142 拓展欧几里得 砝码
- 《FreeSWITCH: VoIP实战》:FreeSWITCH 初步
- 函数式编程 高级集合类和收集器
- u3d单例类
- Java多线程(一)
- HDU5978 To begin or not to begin(概率+规律)
- APP安全报告第十四期:十款热门旅行APP,竟有九款APP的安全评分不及格!
- 【HDU1520】Anniversary Party-树形DP求树的最大权值独立集
- 最长上升子序列,LIS<DP+二分>
- Unity 3D
- 第十天
- GD32F130FXP6学习笔记十一:KEIL MDK输出map文件分析
- 完全背包(装满)模板
- linux中文件颜色,蓝色,白色等各自代表的含义