Light OJ 1027 - A Dangerous Maze(概率)
题目大意:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
const int INF = 1e9+;
const int MAXN = ;
/**
走出来的期望时间 = 需要走次数的期望*平均走一次花费的时间
需要走次数的期望:假设门的总个数是n,可以走出来的门总个数是k,那么我们走出来期望的次数是 n/k.
平均走一次花费的时间: 总时间/n
*/
int gcd(int a,int b)
{
return b == ?a:gcd(b,a%b);
}
int main()
{
int cas = , T, n, a[];
scanf("%d", &T); while(T --)
{
scanf("%d", &n);
int k = , sumTime = ;
for(int i=; i<n; i++)
{
scanf("%d", &a[i]);
sumTime += abs(a[i]);
if(a[i] >= )
k ++;
} printf("Case %d: ", cas ++);
if(k == )
puts("inf");
else
{
int a = gcd(sumTime, k);
printf("%d/%d\n", sumTime/a, k/a);
} } return ;
}
Light OJ 1027 - A Dangerous Maze(概率)的更多相关文章
- Light OJ 1027 - A Dangerous Maze (数学-期望)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1027 题目大意: 一个迷宫, 有n个门,选择一个门花费为|ai|, 如果选择的 ...
- light oj 1027 A Dangerous Maze
一道数学期望题,唉唉,概率论学的不好啊~~ 求走出迷宫的期望时间. 由于有的门会回到起点,所以有可能会走很多遍,设能走出去的门的个数为n1,总的个数为n,那么一次走出去的概率为n1/n,走一次的用的平 ...
- 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 ...
- (期望)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 ...
- 概率好题 Light OJ 1027
题目大意:你在迷宫里,有n扇门,每个门有一个val,这个val可正可负,每次通过一扇门需要abs(x)分钟,如果这个门的val是正的,那么就直接出了迷宫,否则回到原地,问出去迷宫的期望是多少? 思路: ...
- 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 ...
随机推荐
- nginx php7 配置 备用
yum install epel-* -y yum install -y wget unzip gcc gcc-c++ make zlib zlib-devel pcre pcre-devel lib ...
- CentOS 5.4下的Memcache安装步骤(Linux+Nginx+PHP+Memcached)
原文链接:http://www.jb51.net/article/29668.htm
- IOS UIColor 自定义颜色
使用 UIColor定义颜色 和 同 CIColor 与 CGColor 之间的联系.转换 1. 利用UIColor展现 #F6F6F6 这个传统的颜色 #F6F6F6 为一个 16 进制表示的RP ...
- ubuntu12.04安装QQ2013
1.下载Longene QQ2013SP6 http://pan.baidu.com/s/1hq83fWo 2.安装 1)如果之前安装过旧版本需要先卸载(通过dpkg -l | grep qq查看). ...
- 用JS实现版面拖拽效果
类似于这样的一个版面,点击标题栏,实现拖拽效果. 添加onmousedown事件 通过获取鼠标的坐标(clientX,clientY)来改变面板的位置 注意:面板使用绝对定位方式,是以左上角为参考点, ...
- 【POJ2482】【线段树】Stars in Your Window
Description Fleeting time does not blur my memory of you. Can it really be 4 years since I first saw ...
- 【POJ1442】【Treap】Black Box
Description Our Black Box represents a primitive database. It can save an integer array and has a sp ...
- jQuery慢慢啃之核心(一)
1. $("div > p"); div 元素的所有p子元素. $(document.body).css( "background", "bla ...
- <select>与<datalist>的区别
size:下拉框中每次出现选项的个数 multiple:可以一次性选多个选项: disabled:时下拉框不可用,无法点击选项 list:它的值应于id的值对应 datalist要与input标签一 ...
- Linux下定时备份数据库
linux下使用crontab定时备份MYSQL数据库的方法只需按照下面3步做,一切都在你的掌控之下: 第一步:在服务器上配置备份目录代码: mkdir /var/lib/mysqlbackup cd ...