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 ...
随机推荐
- Spring 4.x org.springframework.http.converter.json.MappingJacksonHttpMessageConverter ClassNotFoundException:
Spring 4.x The first major version of Jackson is no longer supported in Spring 4. The class you want ...
- BA Practice Lead Handbook 1 - Why Is Business Analysis Taking The World By Storm?
The articles in this series are focused on individual Business Analysts and their managers. https:// ...
- Decode Ways -- LeetCode
原题链接: http://oj.leetcode.com/problems/decode-ways/ 这道题要求解一个数字串依照字符串编码方式可解析方式的数量.看到这样的求数量的,我们非常easy想 ...
- Chapter 5 - How to Detect the Collisions
Chapter 5 - How to Detect the Collisions Our hero can fire bullets now, but the bullets are only vis ...
- Android(java)学习笔记180:Android MediaPlayer 播放prepareAsync called in state 8解决办法
使用android MediaPlayer播放音频文件时,有时会出现prepareasync called in state 8错误. 以下方法可以避免这个异常出现. 第一种方法: private ...
- majikan
- PHP中用PDO方法打开连接关闭mysql数据库
代码如下: <meta http-equiv="content-type" content="text/html" charset="utf-8 ...
- Linux ssh/scp连接时避免输入yes(公钥验证)并防止出现POSSIBLE BREAK-IN ATTEM
方法一:连接时加入StrictHostKeyChecking=no ssh -o StrictHostKeyChecking=no root@192.168.1.100 方法二:修改/etc/ssh/ ...
- JavaScript的DOM操作(三)
1.相关元素操作: var a = document.getElementById("id"); var b = a.nextSibling,找a的下一个同辈元素,注意空格 var ...
- Sae配置Java数据库连接
Sae配置Java数据库连接 Sae在Java中配置mysql数据库 >>>>>>>>>>>>>>>>& ...