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 nspace 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

3

1

1

2

-10 -3

3

3 -6 -9

Sample Output

Case 1: 1/1

Case 2: inf

Case 3: 18/1

题解:给你n扇门,每扇门都有一个数,k代表从这扇门走k分钟出去,-k代表从这扇门走-k分钟回到原点,让你求出去的期望;

设期望为d 则有(以样例3位例子):d=(3+6+d+9+d)/3;

参考代码为:

 #include<bits/stdc++.h>
using namespace std;
int T,n,a[],sum,cnt; int gcd(int a,int b){ return b==? a:gcd(b,a%b); } int main()
{
scanf("%d",&T);
for(int k=;k<=T;k++)
{
sum=;cnt=;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",a+i),sum+=abs(a[i]);
if(a[i]<) cnt++;
}
if(cnt==n) printf("Case %d: inf\n",k);
else
{
cnt=n-cnt;
if(cnt>sum) swap(cnt,sum);
int num=gcd(sum,cnt);
//int num= __gcd(sum,cnt);
printf("Case %d: %d/%d\n",k,sum/num,cnt/num);
}
} return ;
}

LightOj-1027 A Dangerous Maze(期望)的更多相关文章

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

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

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

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

  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://lightoj.com/volume_showproblem.php?problem=1027 题意:又一个迷宫,有n个门,每个门又一个值num,如果num>0 说明在n ...

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

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

  6. LightOJ 1027 A Dangerous Maze(期望)

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

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

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

  8. LightOj 1027 A Dangerous Maze【概率】

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

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

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

  10. LightOJ - 1027 Dangerous Maze 期望

    你在迷宫中;开始时在你面前看到n扇门.你可以选择你喜欢的任何门.所有门的选择门的概率是相等的. 如果您选择第i个门,它可以让您回到您在xi(xi小于0)分钟内开始的相同位置,也可以在xi(xi大于0) ...

随机推荐

  1. zabbix 4.2 的安装和设置(mysql57----centos7)

    一.安装RPM [root@localhost ~]# rpm -ivh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-release ...

  2. (数据科学学习手札71)在Python中制作个性化词云图

    本文对应脚本及数据已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 一.简介 词云图是文本挖掘中用来表征词频的数据可视化 ...

  3. spring源码1

    1.beans核心类 1.DefaultListableBeanFactory xmlBeanFactory xmlBeanFactory继承自DefaultListableBeanFactory,D ...

  4. JS如何在不给新空间的情况下给数组去重?

    1.先排序,在让相邻元素对比去重 const nums = [3, 1, 1, 5, 2, 3, 4, 3, 5, 5, 6, 4, 6, 6, 6]; Array.prototype.arrayNo ...

  5. ubuntu触摸板双指滑动,页面滚动方向

    setting——mouse & Touchpad——Natural scrolling 跟我的另一台本子一样了-

  6. ubuntu 16.04安装并启动openssh

    对于没有图形界面的linux系统,一般都会用到远程连接控制,,因此新安装的linux系统,在配好网络后,首先要安装的就是远程连接工具,ssh是常用的方法. ps -ef |grep ssh  //查看 ...

  7. 解决php使用支付宝SDK报错问题

    最近公司将一些项目转移了服务器,后来发现使用支付宝支付时发现出现错误,错误如下: 1 The each() function is deprecated. This message will be s ...

  8. Android官方提供的支持不同屏幕大小的全部方法(转)

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/8830286 原文地址为:http://developer.android.com/ ...

  9. CSS中选择器优先级与!important权重使用

    CSS中的选择器优先级与!important权重使用 .class选择器要高于标签选择器. #id选择器要高于.class选择器. 标签选择器是优先级最低的选择器. !important的属性它的权重 ...

  10. 2019-11-7:sql注入防御,webshell概念,学习笔记

    sql注入防护GPC,magic_quotes_gpc函数在php中的作用是判断解析用户提示的数据,如包括有:post.get.cookie过来的数据增加转义字符“\”,以确保这些数据不会引起程序,特 ...