LightOj_1027 A Dangerous Maze
题意:
你在一个迷宫里, 开始的时候你面前有n个门, 选择每个门的概率相等, 有两种结果:
1)回到|x|分钟之前(x为负时)
2)x分钟之后出迷宫(x为正时)
每次回到|x|分钟之前, 你都记不得你曾经选过哪扇门
问走出迷宫所用时间的期望。
思路:
因为每次都不记得曾经的选择, 所以每次的期望都是一样的。
设,T1为每次走出去所用时间的期望, T2为回到之前所用时间的期望。
则E = p * T1 + (T2 + E) * (1 - p)
化简后得, p * E = p * T1 + T2 * (1 - p)
假设有m个门是走出去的, 则p = m / n
代进上式得:m * E / n = m * T1 / n + (n - m) * T2 / n
m * E = m * T1 + (n - m) * T2
T1 = (sigma x[i]) / m, x[i] > 0, T2 = (sigma |x[i]|) / (n - m), x[i] < 0
E = (sigma x[i] + sigma |x[i]|) / m
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define MAXN 110
#define MOD 1000000007
#define eps 1e-6
int n;
int t[], m;
int gcd(int a, int b)
{
return b == ? a : gcd(b, a % b);
} int main()
{
int T;
int kcase = ;
scanf("%d", &T);
while(T --)
{
scanf("%d", &n);
m = ;
t[] = t[] = ;
for(int i = ; i < n; i ++)
{
int x;
scanf("%d", &x);
if(x > )
{
t[] += x;
m ++;
}
else
t[] += (- * x);
}
if(!m) printf("Case %d: inf\n", ++ kcase);
else
{
int k = gcd(t[] + t[], m);
printf("Case %d: %d/%d\n", ++ kcase, (t[] + t[]) / k, m / k);
}
}
return ;
}
LightOj_1027 A Dangerous Maze的更多相关文章
- [LOJ 1027] Dangerous Maze
A - A Dangerous Maze Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- [LightOJ 1027] A Dangerous Maze
A Dangerous Maze You are in a maze; seeing n doors in front of you in beginning. You can choose any ...
- A Dangerous Maze (II) LightOJ - 1395(概率dp)
A Dangerous Maze (II) LightOJ - 1395(概率dp) 这题是Light Oj 1027的加强版,1027那道是无记忆的. 题意: 有n扇门,每次你可以选择其中一扇.xi ...
- LightOJ - 1395 A Dangerous Maze (II) —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1395 1395 - A Dangerous Maze (II) PDF (English) Statistic ...
- LightOJ - 1027 A Dangerous Maze —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1027 1027 - A Dangerous Maze PDF (English) Statistics For ...
- Lightoj 1027 - A Dangerous Maze 【期望】
1027 - A Dangerous Maze PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Y ...
- (期望)A Dangerous Maze(Light OJ 1027)
http://www.lightoj.com/volume_showproblem.php?problem=1027 You are in a maze; seeing n doors in fron ...
- LightOj-1027 A Dangerous Maze(期望)
You are in a maze; seeing n doors in front of you in beginning. You can choose any door you like. Th ...
- LightOJ-1027-A Dangerous Maze(概率)
链接: https://vjudge.net/problem/LightOJ-1027#author=634579757 题意: You are in a maze; seeing n doors i ...
随机推荐
- Cocos2d-js 3.0 alp2 使用指南
Download Cocos2d-JS: http://www.cocos2d-x.org/download Unzip and copy to C:/ Download JDK: http://ww ...
- springMVC3学习(八)--全球异常处理
在springMVC在配置文件: <bean id="exceptionResolver" class="org.springframework.web.servl ...
- 通过源码看android系列之multidex库
我们在开发项目时,喜欢引入好多的第三方包,大大的方便了我们的开发,但同时,因为android方法总数的限制,不能超过65k,然而呢,随着我们的开发,65k最终还是会超过,所以,google就给出了这个 ...
- fscanf函数
函数定义: int fscanf( FILE *stream, const char *format [, argument ]... ); 以下是csdn的样例: /* FSCANF.C: This ...
- mysql 导入excel 或 .csv
第一步 导出excel 去掉列头,设置文本里面格式
- DevExpress的GridView设置特定行的样式
GridView控件绑定事件: gridView_SampleData.CustomDrawCell += gridView_SampleData_CustomDrawCell; 根据自定义逻辑来改变 ...
- Winform中修改WebBrowser控件User-Agent的方法(已经测试成功)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...
- Objective-C 内存管理与高级环境编程 阅读分享
常用的调试私有API uintptr_t objc_rootRetainCount(id obj) _objc_autoreleasePoolPrint();//查看自动释放池中的对象 LLVM cl ...
- 父页面iframe自动适应子页面的宽高度
<script type="text/javascript"> function load(){ parent.document.getElementById(&quo ...
- 完美解决 未能打开编辑器:Unmatched braces in the pattern.
Eclipse出现这个问题而不能查看源代码 原因就是语言包的问题 出现这个问题了 一定是安装了中文或者多国语言包 下面我就来交大家解决的办法 超简单的 第一步 配置自己Eclipse的启动参数 ecl ...