(期望)A Dangerous Maze(Light OJ 1027)
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.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case contains a blank line and an integer n (1 ≤ n ≤ 100) denoting the number of doors. The next line contains n space separated integers. If the ith integer (xi) is positive, you can assume that the ith door will take you out of maze after xi minutes. If it's negative, then the ith door will take you back to the beginning position after abs(xi) minutes. You can safely assume that 1 ≤ abs(xi) ≤ 10000.
Output
For each case, print the case number and the expected time to get out of the maze. If it's impossible to get out of the maze, print 'inf'. Print the result in p/q format. Where p is the numerator of the result and q is the denominator of the result and they are relatively prime. See the samples for details.
Sample Input |
Output for Sample Input |
|
3 1 1 2 -10 -3 3 3 -6 -9 |
Case 1: 1/1 Case 2: inf Case 3: 18/1 |
题目大意:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef unsigned long long LL;
#define met(a,b) (memset(a,b,sizeof(a)))
const int INF = 1e9+;
const int maxn = ;
const int MOD = ; int gcd(int a, int b)
{
return b==?a:gcd(b,a%b);
} int main()
{
int T, iCase=;
scanf("%d", &T);
while(T--)
{
int n, time, i, sum=, k=; scanf("%d", &n); for(i=; i<=n; i++)
{
scanf("%d", &time);
if(time>) k++;
sum += abs(time);
} int w = gcd(sum, k); if(!k)
printf("Case %d: inf\n", iCase++);
else
printf("Case %d: %d/%d\n", iCase++, sum/w, k/w); }
return ;
}
/** */

(期望)A Dangerous Maze(Light OJ 1027)的更多相关文章
- Light OJ 1027 - A Dangerous Maze (数学-期望)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1027 题目大意: 一个迷宫, 有n个门,选择一个门花费为|ai|, 如果选择的 ...
- Light OJ 1027 - A Dangerous Maze(概率)
题目大意: 你在一个迷宫里,你面前有n个门,你选择门的概率是一样的,每扇门有一个数字k, 加入这个数字是负数,那么这个门会花费你abs(k)分钟后把你带回原点, 假如这个数字是正数,他可以把你带出迷宫 ...
- light oj 1027 A Dangerous Maze
一道数学期望题,唉唉,概率论学的不好啊~~ 求走出迷宫的期望时间. 由于有的门会回到起点,所以有可能会走很多遍,设能走出去的门的个数为n1,总的个数为n,那么一次走出去的概率为n1/n,走一次的用的平 ...
- 概率好题 Light OJ 1027
题目大意:你在迷宫里,有n扇门,每个门有一个val,这个val可正可负,每次通过一扇门需要abs(x)分钟,如果这个门的val是正的,那么就直接出了迷宫,否则回到原地,问出去迷宫的期望是多少? 思路: ...
- A Dangerous Maze (II) LightOJ - 1395(概率dp)
A Dangerous Maze (II) LightOJ - 1395(概率dp) 这题是Light Oj 1027的加强版,1027那道是无记忆的. 题意: 有n扇门,每次你可以选择其中一扇.xi ...
- 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 ...
- [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 ...
随机推荐
- Unity3D中制作Loading场景进度条
背景 通常游戏的主场景包含的资源较多,这会导致加载场景的时间较长.为了避免这个问题,可以首先加载Loading场景,然后再通过Loading场景来加载主场景.由于Loading场景包含的资源较少,所以 ...
- c程序中出现segment error 和 bus error 的原因
在c程序中,经常会遇到段错误(segment error)和总线错误(bus error),这两种问题出现的原因可能如下 段错误: 对一个NULL指针解引用. 访问程序进程以外的内存空间. 实际上,第 ...
- Android学习---通过内容提供者(ContentProvider)操作另外一个应用私有数据库的内容
一.什么是ContentProvider? ContentProvider直译过来就是内容提供者,主要作用就是A应用提供接口给B应用调用数据,和之前介绍的sharedPreference和直接开放文件 ...
- java8中CAS的增强
注:ifeve.com的同名文章为本人所发,此文在其基础做了些调整.转载请注明出处! 一.java8中CAS的增强 前些天,我偶然地将之前写的用来测试AtomicInteger和synchronize ...
- hibernate基础
另存为查看吧
- python smtplib发送邮件遇到的认证问题
python的smtplib模块主要是用来发送邮件的,使用起来比较方便. 使用程序发送邮件只需要写以下几行代码就OK了: #!/usr/bin/env python import smtplib s ...
- PHP的文件格式应该以UTF-8无BOM编码
前一段时间写PHP,经常在解析文件之前就要对数据进行处理判断,并以header()的方式进行页面跳转.然而后来将文件放到 linux 服务器时常碰到header()解析出错的情况,而在 windows ...
- shell <<EOF
1.考虑下面的需求,在主shell执行命令,进入其他的命令,后面的输入,想作为命令的输入,而不是主shell的输入,怎么办? 2.使用<<EOF,告诉主shell,后续的输入,是其他命令或 ...
- 3G产品升级相关知识
1.3G产品升级时,内核,文件系统,boot,应用程序,全都升级了,是在boot里升的; 2.拨号模式里的 chap:公网; pap:专网 3.用来查看U盘挂在哪个目录下: cat /proc/par ...
- (重要)使用廉价的VPN隐私会被窥探
使用廉价的VPN可以节省一部分的支出,但是损失的却是我们的网上隐私,很多部门都很关心我们在网上干些什么,本来使用VPN是为了保护自己的隐私不被窥探,很显然这是事与愿违的,一些小公司或者大公司,通过提供 ...