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 ...
随机推荐
- 如何利用 _ViewStart.cshtml对页面添加代码?
_ViewStart.cshtml 添加的代码会出现在页面的最上面(<html> 之前) .这样就造成了我原先很多页面出现兼容性问题(经难是因为<html>之前出现了其它的代码 ...
- PrintWriter的print和write方法(转)
public void print(String s) {if (s == null) {s = "null";}write(s); } print只是先对s==null转换为 ...
- 运行codeblocks时出现的问题解决
When I try running Code::Blocks, I get the following error message: Another program instance is alre ...
- linux常用的压缩与解压缩命令 分类: 学习笔记 linux ubuntu 2015-07-05 19:38 38人阅读 评论(0) 收藏
1.gzip 压缩 gzip 是压缩文件,压缩之后文件后缀为.gz 用法:gzip 选项 [文件] 2.gunzip 解压 这个命令与gzip的功能刚好相反,这个是解压. 用法 gunzip 选项 [ ...
- WTL 自定义 Button类-自绘
WTL 自绘Button类,支持按钮三种形态,正常模式,hover模式,鼠标按下模式,支持png图片.使用方法很简单: MyButton* pButton = new MyButton; pBut ...
- VIM中文乱码(_vimrc配置文件备份)
_vimrc在用户目录下: set fileencodings=ucs-bom,utf-,cp936,gb18030,big5,euc-jp,euc-kr,latin1 set encoding=ut ...
- Unity3D中读取CSV文件
直接上代码 Part1: using UnityEngine; using System.IO; using System.Collections.Generic; public class CSV ...
- 最近有机会接触到了angularJs
记点笔记 概念多了 理顺还待时日: 总的来说: 1.ng-src src属性 2.ng-href href属性 3.ng-checked 选中状态 4.ng-selected 被选择状态 5.ng- ...
- 浅析Activity不可见与透明
http://blog.csdn.net/lincyang/article/details/6868582 看见标题也许你会有疑问,不可见和透明不是一个意思吗? 从字面上看,这还真是差不多.但在Act ...
- MongoDB的查询
一.Find操作 二.分页和排序 三.游标的使用 一.Find查询 事前准备:插入如下数据 db.Students.insert([ { _id:1, name:"Zhao", a ...