LightOJ-1027-A Dangerous Maze(概率)
链接:
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(概率)的更多相关文章
- Lightoj 1027 - A Dangerous Maze 【期望】
1027 - A Dangerous Maze PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Y ...
- LightOJ - 1027 A Dangerous Maze —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1027 1027 - A Dangerous Maze PDF (English) Statistics For ...
- [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 ...
- LightOj 1027 A Dangerous Maze【概率】
题目链接:http://www.lightoj.com/volume_showproblem.php? problem=1027 题意: 你面前有n个门,每一个相应一个数字,若为正xi.代表xi分钟后 ...
- LightOJ 1027 - A Dangerous Maze(求期望)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1027 题意:又一个迷宫,有n个门,每个门又一个值num,如果num>0 说明在n ...
- LightOJ 1027 A Dangerous Maze(期望)
https://cn.vjudge.net/problem/LightOJ-1027 题意:有n扇门,每扇门有个时间ti,选择正数的门可以在ti后带你走出迷宫,负数的门会在ti后带你回到起点,然后重新 ...
- LightOJ 1027 A Dangerous Maze(期望)题解
题意:n扇门,每扇门后都有一个值x,如果x<0会让你等待-x再重新回到这里选择门,x>0你经过x时间就会被传送走,问你被传送走的期望 思路:假设被传送走的期望为E,那么对于x<0来说 ...
- LightOJ 1027 A Dangerous Maze (数学期望)
题意:你面前有 n 个门,每次你可以选择任意一个进去,如果xi是正数,你将在xi后出去,如果xi是负数,那么xi后你将回来并且丢失所有记忆,问你出去的期望. 析:两种情况,第一种是直接出去,期望就是 ...
- LightOJ - 1395 A Dangerous Maze (II) —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1395 1395 - A Dangerous Maze (II) PDF (English) Statistic ...
- Light OJ 1027 - A Dangerous Maze(概率)
题目大意: 你在一个迷宫里,你面前有n个门,你选择门的概率是一样的,每扇门有一个数字k, 加入这个数字是负数,那么这个门会花费你abs(k)分钟后把你带回原点, 假如这个数字是正数,他可以把你带出迷宫 ...
随机推荐
- Linux C\C++基础 字符数组、字符串和字符串常量
1.字符数组和字符串 C语言没有字符串类型,用字符数组模拟 字符串一定是字符数组,字符数组不一定是字符串 如果字符数组以字符'\0'('\0'等同与数字0)结尾,那么这个字符数组就是字符串 char ...
- 应用安全 - PHP - CMS - DeDeCMS - 漏洞 - 汇总
SSV-97074 Date 类型 前台任意密码修改 影响范围 前置条件 CVE-2018-20129 Date 类型前台文件上传 影响范围 前置条件(1)前台登录(2)/member/article ...
- stack smashing detected解决过程
在执行程序结束return 0 之后出现上图问题.主要原因是在程序中存在数组越界. 解决方法: 1. 查看定义的结构体内buffer大小,为4096字节 typedef struct { UINT32 ...
- CVE-2018-2628
哈哈哈,终于等到我复现一个CVE漏洞了. 漏洞描述 Oracle Fusion Middleware(Oracle融合中间件)是美国甲骨文(Oracle)公司的一套面向企业和云环境的业务创新平台.该平 ...
- 将对象以json格式写入到文件中
将 list 对象以json格式写入到文件中 try { ObjectMapper mapper = new ObjectMapper(); String value = mapper.writeVa ...
- spring5源码分析系列(三)——IOC容器的初始化(一)
前言: IOC容器的初始化包括BeanDefinition的Resource定位.载入.注册三个基本过程. 本文以ApplicationContext为例讲解,XmlWebApplicationCon ...
- linux centos7.3安装lnmp,nginx-1.11.12 ,php7.0.2 ,
#更新源 yum -y update #添加用户和组 adduser www groupadd www usermod -G www www #初始化目录 mkdir -p /data/app/php ...
- redis在php中实际应用-hash
Redis hash 是一个string类型的field和value的映射表,hash特别适合用于存储对象. 目录: 1.批量赋值:hmset,hmget,hgetall 可用于存储一条条数据,即一个 ...
- python 变量 (全面不一样的变量)
变量 一:什么是变量? 变量即变化的量,核心是"变"与"量"二字,变即变化,量即衡量状态 变:状态是会发生改变的 量:记录现实世界中的状态,让计算机能够像人一样 ...
- leecode100热题 HOT 100
# 题名 题解 通过率 难度 出现频率 1 两数之和 46.5% 简单 2 两数相加 35.5% 中等 3 无重复字符的最长子串 31.1% ...