链接:

https://vjudge.net/problem/LightOJ-1027#author=634579757

题意:

You are in a maze; seeing n doors in front of you in beginning. You can choose any door you like. The probability for choosing a door is equal for all doors.

If you choose the ith door, it can either take you back to the same position where you begun in xi minutes, or can take you out of the maze after xi minutes. If you come back to the same position, you can't remember anything. So, every time you come to the beginning position, you have no past experience.

Now you want to find the expected time to get out of the maze.

思路:

考虑当x大于0则出去的期望时间为1/nt,如果小于0出去的期望时间为1/n(t+d).其中d为整体出去的期望时间。

推出d = 1/nsumt+ne/nd.其中sumt为总时间及abs(t)的和。ne为负值的们。

代码:

#include <iostream>
#include <memory.h>
#include <string>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <algorithm>
#include <map>
#include <queue>
#include <math.h>
#include <cstdio>
#include <set>
#include <iterator>
#include <cstring>
#include <assert.h>
using namespace std; typedef long long LL; int n; int main()
{
int t, cnt = 0;
scanf("%d",&t);
while (t--)
{
scanf("%d", &n);
int sum = 0, ne = 0, v;
bool flag = false;
for (int i = 1;i <= n;i++)
{
scanf("%d", &v);
if (v > 0)
flag = true;
if (v < 0)
ne++;
sum += abs(v);
}
if (!flag)
printf("Case %d: inf\n", ++cnt);
else
printf("Case %d: %d/%d\n", ++cnt, sum/__gcd(sum, n-ne), (n-ne)/__gcd(sum, n-ne));
} return 0;
}

LightOJ-1027-A Dangerous Maze(概率)的更多相关文章

  1. Lightoj 1027 - A Dangerous Maze 【期望】

    1027 - A Dangerous Maze PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Y ...

  2. LightOJ - 1027 A Dangerous Maze —— 期望

    题目链接:https://vjudge.net/problem/LightOJ-1027 1027 - A Dangerous Maze    PDF (English) Statistics For ...

  3. [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 ...

  4. LightOj 1027 A Dangerous Maze【概率】

    题目链接:http://www.lightoj.com/volume_showproblem.php? problem=1027 题意: 你面前有n个门,每一个相应一个数字,若为正xi.代表xi分钟后 ...

  5. LightOJ 1027 - A Dangerous Maze(求期望)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1027 题意:又一个迷宫,有n个门,每个门又一个值num,如果num>0 说明在n ...

  6. LightOJ 1027 A Dangerous Maze(期望)

    https://cn.vjudge.net/problem/LightOJ-1027 题意:有n扇门,每扇门有个时间ti,选择正数的门可以在ti后带你走出迷宫,负数的门会在ti后带你回到起点,然后重新 ...

  7. LightOJ 1027 A Dangerous Maze(期望)题解

    题意:n扇门,每扇门后都有一个值x,如果x<0会让你等待-x再重新回到这里选择门,x>0你经过x时间就会被传送走,问你被传送走的期望 思路:假设被传送走的期望为E,那么对于x<0来说 ...

  8. LightOJ 1027 A Dangerous Maze (数学期望)

    题意:你面前有 n 个门,每次你可以选择任意一个进去,如果xi是正数,你将在xi后出去,如果xi是负数,那么xi后你将回来并且丢失所有记忆,问你出去的期望. 析:两种情况,第一种是直接出去,期望就是 ...

  9. LightOJ - 1395 A Dangerous Maze (II) —— 期望

    题目链接:https://vjudge.net/problem/LightOJ-1395 1395 - A Dangerous Maze (II)    PDF (English) Statistic ...

  10. Light OJ 1027 - A Dangerous Maze(概率)

    题目大意: 你在一个迷宫里,你面前有n个门,你选择门的概率是一样的,每扇门有一个数字k, 加入这个数字是负数,那么这个门会花费你abs(k)分钟后把你带回原点, 假如这个数字是正数,他可以把你带出迷宫 ...

随机推荐

  1. CentOS 7 安装java 环境

    1.创建安装目录 mkdir /usr/local/java/ 2.将下载的安装包 上传到 安装目录   (可用Xftp 上传) 3.解压 tar -xzvf jdk-8u221-linux-x64. ...

  2. C#DataGridView格式化显示单元格的内容

    今天又发现了一个很有用的东西,DataGridView的CellFormating事件 经常从数据库查到的原始数据需要经过转换之后显示在客户端,比如性别,“1”显示“男”,“0”显示“女”,为此经常将 ...

  3. 小菜鸟之java异常

    一.异常简介 什么是异常? 异常就是有异于常态,和正常情况不一样,有错误出错.在java中,阻止当前方法或作用域的情况,称之为异常. java中异常的体系是怎么样的呢? 1.Java中的所有不正常类都 ...

  4. jsp文件

    新建的jsp文件比新建的html文件多了一行内容<%@ page contentType="text/html; charset=utf-8" %>,这样不会显示乱码 ...

  5. Maven添加镜像仓库、更改本地仓库位置

    添加镜像仓库 在conf目录下的settings.xml文件的145行左右 id表示该镜像的id mirrorOf表示为哪个仓库配置镜像,central为默认的中央仓库的id,也可以使用通配符*,来匹 ...

  6. C语言&*符号使用及大端法小端法测试

    工具:Microsoft Visual C++ 6.0 例子: int a = 1; int* b = &a; C语言规定a表示存储单元中的数据,&a表示存储单元的地址,b存储的就是a ...

  7. LOJ526「LibreOJ β Round #4」子集

    题目 算是比较裸的题吧. 首先我们把符合要求的\((i,j)\)建一条边,那么我们要求的就是最大团. 转化为补图的最小独立集. 然后我们来证明补图是一个二分图. \((u,v)\)有边\(\Leftr ...

  8. 坦克大战--Java类型 ---- (1)音乐播放

    实现原理 我用接口java.applet.AudioClip实现音乐播放,那么我们需要了解这个接口的情况. 我们主要使用其中的三个方法: (1)void loop(); //循环播放(2)void p ...

  9. Kinect开发-Hello Kinect

    置好开发环境后,首先测试下是否真的完成,也就是能够正常进行开发.此时,当然就得祭出Hello World大法! 1.首先创建一个WPF Application工程,之后添加对Microsoft.Kin ...

  10. 数据库oracle行列的操作(MiTAC)

    1.两个重要的网址(参考): http://lovejuan1314.iteye.com/blog/413694http://www.cnblogs.com/heekui/archive/2009/0 ...