option=com_onlinejudge&Itemid=8&page=show_problem&problem=2652" style="">题目链接:uva 11605 - Lights inside a 3d Grid

题目大意:给定一个三维坐标系大小,每一个位置有一个灯。初始状态为关。每次随机选中两个点,以这两点为对角线的长方体内全部灯转变状态。操作K次。问说平均情况下。最后会有多少栈灯亮着。

解题思路:枚举坐标系上的点。计算单个点亮着的概率,然后累加即使总体的期望。

对于一个点x,y,z,分别考虑每维坐标系,比如x。选中的概率为px=2∗(n−x+1)∗x−1n∗n,三维坐标均选中的概率p即为该点被选中的概率。

可是对于一点来说,由于操作K次,所以最后灯为亮的话。操作到灯的次数一定要为奇数才行,所以有∑C(iK)pi(1−p)K−i(i为奇数)

===》(1−p+p)K−(1−p−p)K2

===》1−(1−2p)K2

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm> using namespace std; int N, M, P, K; inline double getp (double n, double x) {
double s = n * n;
double t = 2 * (n - x + 1) * x - 1;
return t / s;
} inline double handle (double p) {
return (1 - pow(1 - 2 * p, K)) / 2;
} double solve () {
double ret = 0;
for (int x = 1; x <= N; x++) {
double px = getp(N, x);
for (int y = 1; y <= M; y++) {
double py = getp(M, y);
for (int z = 1; z <= P; z++) {
double pz = getp(P, z);
ret += handle(px * py * pz);
}
}
}
return ret;
} int main () {
int cas;
scanf("%d", &cas);
for (int kcas = 1; kcas <= cas; kcas++) {
scanf("%d%d%d%d", &N, &M, &P, &K);
printf("Case %d: %.10lf\n", kcas, solve());
}
return 0;
}

uva 11605 - Lights inside a 3d Grid(概率)的更多相关文章

  1. UVA 11605 Lights inside a 3d Grid —— (概率和期望)

    题意:见大白书P181. 分析:一个一个点的进行分析,取其期望然后求和即可.假设当前点在第一次中被选到的概率为p,f[i]表示进行k次以后该点亮的概率(在这里也可以理解为期望),g[i]表示k次后该点 ...

  2. UVA 11605 Lights inside a 3d Grid

    #include <iostream> #include <stdio.h> #include <cstring> #include <math.h> ...

  3. Lights inside a 3d Grid UVA - 11605(概率)

    题意: 给出一个n * m * h的空间 每次任意选择两个点  使得在以这两个点连线为对角线的空间的点的值 取反  (初始为0) 求经过k次操作后最后有多少点的值为1 解析: 遇到坐标分维去看  把三 ...

  4. LightOJ1284 Lights inside 3D Grid (概率DP)

    You are given a 3D grid, which has dimensions X, Y and Z. Each of the X x Y x Z cells contains a lig ...

  5. LightOJ 1284 - Lights inside 3D Grid 概率/期望/二项式定理

    题意:给你一个长宽高为x,y,z的长方体,里面每个格子放了灯,再给你k次选取任意长方体形状的区块,对其内所有灯开或关操作,初始为关,问亮灯数量的期望值. 题解:首先考虑选取区块的概率,使某个灯在被选取 ...

  6. Lights inside 3D Grid LightOJ - 1284 (概率dp + 推导)

    Lights inside 3D Grid LightOJ - 1284 题意: 在一个三维的空间,每个点都有一盏灯,开始全是关的, 现在每次随机选两个点,把两个点之间的全部点,开关都按一遍:问k次过 ...

  7. LightOJ - 1284 Lights inside 3D Grid (概率计算)

    题面: You are given a 3D grid, which has dimensions X, Y and Z. Each of the X x Y x Z cells contains a ...

  8. LightOJ - 1284 Lights inside 3D Grid —— 期望

    题目链接:https://vjudge.net/problem/LightOJ-1284 1284 - Lights inside 3D Grid    PDF (English) Statistic ...

  9. 3D Grid Effect – 使用 CSS3 制作网格动画效果

    今天我们想与大家分享一个小的动画概念.这个梦幻般的效果是在马库斯·埃克特的原型应用程序里发现的​​.实现的基本思路是对网格项目进行 3D 旋转,扩展成全屏,并呈现内容.我们试图模仿应用程序的行为,因此 ...

随机推荐

  1. 看无可看 分治FFT+特征值方程

    题面: 看无可看(see.pas/cpp/c) 题目描述 “What’s left to see when our eyes won’t open?” “若彼此瞑目在即,是否终亦看无可看?” ---- ...

  2. MaBatis配置(单配置 之一)

    注: 此文中的实体类还是沿用上一章的Emp和Dept两个类 .引入需要的jar包文件:http://pan.baidu.com/s/1qYy9nUc :mybatis-3.2.2.jar .编写MyB ...

  3. 将电脑浏览器User-Agent识别改成手机浏览器UA几种简单方法

    第一种方法:修改浏览器的快捷方式 右击桌面上的Chrome浏览器图标,在弹出的右键菜单中选择“复制”,复制一个图标副本到桌面.右击该副本,选择“属性”,打开相应的对话框,在“目标”文本框的字符后面添加 ...

  4. 关于onActivityResult方法不执行的问题汇总

    我们不生产代码, 只是大自然的搬运工.  首先致谢: https://blog.csdn.net/sbvfhp/article/details/26858441 场景描述: 在A activity(由 ...

  5. ffmpeg rtp时间戳

    ffmpeg rtp时间戳 ffmpeg  c  一.介绍 在ffmpeg中,每帧都会存在一个pts用来表示该帧图像在视频流中的位置.而在多路流(比如视频.音频)时,往往需要进行多媒体的同步,使得画面 ...

  6. Ubuntu Mysql 常用指令

    mysql 常用指令及中文乱码解决 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...

  7. ubuntu 更改终端颜色

    1.$ sudo gedit .bashrc 2.PS1="\[\033[1;36;01m\]\u\[\033[00m\]\[\033[1;34;01m\]@\[\033[00m\]\[\0 ...

  8. excel 类获取起始列和使用列

    m_excel.OpenWorkBook(sFileName, sSheetDrawingList); // Get drawing info int iStartRow = 0, iStartCol ...

  9. 用C#在Visual Studio写Javascript单元测试

    1.在vs创建一个标准的单元测试工程 2.引用nuget包:Edge.js 我是用的是6.11.2版本 3.编写JsRunner类 using EdgeJs; using System; using ...

  10. 原生js实现瀑布流效果

    参考此篇:https://segmentfault.com/a/1190000012621936 以下为个人测试中: css: .masonry{ width:100%; } .item{ posit ...