Day11 - F - A Dangerous Maze LightOJ - 1027
求期望注意期望的定义,这题我们可以分正负数情况,设所求期望为E
正数: 1/n*x_i
负数:1/n*(E+x_j) 此时概率为1/n,根据期望定义,他回到起点后出去的期望为E,花费回起点的时间为x_j,也就是该点的取值情况
整理上式 E = sum / cnt_i sum是所有绝对值和, cnt_i是正数数量
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL;
typedef pair<int,int> pii; const int maxm = ;
int buf[maxm]; inline int gcd(int a, int b) {
return b == ?a:gcd(b,a%b);
} void run_case() {
int n; cin >> n;
bool flag = false;
int ans = , cnt = ;
for(int i = ; i < n; ++i) {
cin >> buf[i];
ans += abs(buf[i]);
if(buf[i] > ) cnt++;
}
if(cnt) {
int div = gcd(ans, cnt);
cout << ans/div << "/" << cnt / div << "\n";
} else {
cout << "inf\n";
}
} int main() {
//ios::sync_with_stdio(false), cin.tie(0);
cout.flags(ios::fixed);cout.precision();
int t; cin >> t;
//while(t--)
for(int i = ; i <= t; ++i) {
cout << "Case " << i << ": ";
run_case();
}
//cout.flush();
return ;
}
Day11 - F - A Dangerous Maze LightOJ - 1027的更多相关文章
- A Dangerous Maze LightOJ - 1027
这题意真是... 题意:你在一个迷宫里,有一些门,每个门有一个参数x,如果为正表明你进入门后可以花x的时间出去,如果为负表明你进入门后可以花-x的时间回到出发的地方.每次回到出发的地方之后,不能记得之 ...
- 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 ...
- [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 (II) LightOJ - 1395(概率dp)
A Dangerous Maze (II) LightOJ - 1395(概率dp) 这题是Light Oj 1027的加强版,1027那道是无记忆的. 题意: 有n扇门,每次你可以选择其中一扇.xi ...
- LightOJ - 1395 A Dangerous Maze (II) —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1395 1395 - A Dangerous Maze (II) PDF (English) Statistic ...
- [LOJ 1027] Dangerous Maze
A - A Dangerous Maze Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- LightOJ 1027 - A Dangerous Maze(求期望)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1027 题意:又一个迷宫,有n个门,每个门又一个值num,如果num>0 说明在n ...
- LightOj 1027 A Dangerous Maze【概率】
题目链接:http://www.lightoj.com/volume_showproblem.php? problem=1027 题意: 你面前有n个门,每一个相应一个数字,若为正xi.代表xi分钟后 ...
随机推荐
- 1+x证书Web 前端开发初级——理论考试(试卷1)
1+x证书Web 前端开发初级——理论考试(试卷1) 一.单选题(每小题 2 分,共 30 小题,共 60 分) 1.HTML 语言中,设置表格中文字与边框距离的标签是() A.<table b ...
- 计算几何-Dot-Vector
This article is made by Jason-Cow.Welcome to reprint.But please post the article's address. 看了书,然后码 ...
- PHP 源码 —— is_array 函数源码分析
is_array 函数源码分析 本文首发于 https://github.com/suhanyujie/learn-computer/blob/master/src/function/array/is ...
- git相关项目迁移
1). 从原地址克隆一份裸版本库,比如原本托管于 GitHub. git clone --bare git://github.com/username/project_old.git --bare 创 ...
- linux日常运维工作
Linux的使用环境也日趋成熟,各种开源产品络绎不绝,大有百花齐放的盛景,那么当Linux落地企业,回归工作时,我们还要面对这Linux运维方面的诸多问题,今天我们特意组织一场有关Linux 在企业运 ...
- js加密(八)新浪微博登录
1. url: https://weibo.com/ 2. target: 登录 3. 分析.由于需要填写验证码,本篇只分析破解用户名和密码加密部分,不做验证码识别. 3.1 老规矩,F12,随便输入 ...
- 负环--spfa
洛谷板子题 负环?是有负权边的环还是一个边权之和为负的环? 还没有准确的定义(那就先忽略吧qwq 判断负环的方法: 暴力枚举/spfa/mellman—ford/奇怪的贪心/超神的搜索 可惜我只会sp ...
- opencv:图形绘制与填充
#include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace st ...
- PAT 1014 Waiting in Line (模拟)
Suppose a bank has N windows open for service. There is a yellow line in front of the windows which ...
- KafKa集群安装、配置
一.事前准备 1.kafka官网:http://kafka.apache.org/downloads. 2.选择使用版本下载. 3.kafka集群环境准备:(linux) 192.168.145.12 ...