题面:

You are given a 3D grid, which has dimensions X, Y and Z. Each of the X x Y x Z cells contains a light. Initially all lights are off. You will have K turns. In each of the K turns,

....

题意:

一个大立方体里面选择k次小的立方体,将小的立方体里面灯泡的开关按一下,问最后的小灯泡亮起的个数期望

思路:

单独计算每个点的贡献

设\(f(x)\)是一共按了x次开关,某一个小灯泡被按了奇数次的概率,\(p\)是某一次被按下的概率

其中 \(f(1) = p\)

所以,有以下公式

\[f(k)=(1-p)f(k-1)+p(1-f(k-1))
\]

化简得:

\[f(k)=(1-p)f(k-1)+p-p*f(k-1)
\]

\[f(k)=(1-2p)f(k-1)+p
\]

同理:

\[f(k-1)=(1-2p)f(k-2)+p
\]

代入\(f(k)\):

\[f(k) = (1-2p)[(1-2p)f(k-2)+p]+p
\]

\[f(k) = (1-2p)^2f(k-2)+p+p(1-p)
\]

写出\(f(k-2)\),并代入上式,可得:

\[f(k) = (1-2p)^3f(k-3)+p+p(1-p)+p(1-2p)^2
\]

...

递推可得:

\[f(k) = (1-2p)^{k-1}f(1) + p(1-2p)^{k-2}+p(1-2p)^{k-3}+...+p
\]

通过等比数列求和:

\[f(x)=(1-2p)^{k-1}*p+[1-(1-2*p)^{k-1}]/2
\]

化简得:

\[f(x) = [1-(1-2*p)^{k}]/2
\]

其中,\(p\)的计算方法为,分别计算\(x,y,z\)被选中的概率,再相乘

#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define debug(a,i) cout<<#a<<"["<<i<<"] = "<<a[i]<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 100086;
const int maxm = 100086;
const int inf = 2.1e9;
const ll Inf = 999999999999999999;
const int mod = 1000000007;
const double eps = 1e-6;
const double pi = acos(-1); double q_pow(double a,int b){
double ans=1;
while(b){
if(b&1){
ans*=a;
}
a*=a;
b>>=1;
}
return ans;
} double f(double p,int k){
if(k==0){return 0;}
double tmp = q_pow(1.0-2*p,k);
return (1.0-tmp)/2;
}
double f1(double p,int k){
if(k==0){return 0;}
if(k==1){return p;}
return (1.0-2*p)*f1(p,k-1)+p;
} int main()
{
// ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE int T;
scanf("%d",&T);
int cas = 0;
while(T--){
int x,y,z,K;
scanf("%d%d%d%d",&x,&y,&z,&K);
int sum = x*y*z;
double ans = 0;
for(int i=1;i<=x;i++){
for(int j=1;j<=y;j++){
for(int k=1;k<=z;k++){
double p1 = 1.0-1.0*((i-1)*(i-1)+(x-i)*(x-i))/(x*x);
double p2 = 1.0-1.0*((j-1)*(j-1)+(y-j)*(y-j))/(y*y);
double p3 = 1.0-1.0*((k-1)*(k-1)+(z-k)*(z-k))/(z*z);
double pp = p1*p2*p3;
ans+=f(pp,K);
}
}
}
printf("Case %d: %f\n",++cas,ans);
} return 0;
}

LightOJ - 1284 Lights inside 3D Grid (概率计算)的更多相关文章

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

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

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

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

  3. 【非原创】LightOJ - 1284 Lights inside 3D Grid【概率期望】

    学习博客: 戳这里 戳这里 戳这里 戳这里 题意: 在一个三维的空间,每个点都有一盏灯,开始全是关的, 现在每次随机选两个点,把两个点之间的全部点,开关都按一遍:问k次过后开着的灯的期望数量: 题解: ...

  4. LightOJ 1284 Lights inside 3D Grid (数学期望)

    题意:在一个三维的空间,每个点都有一盏灯,开始全是关的.现在每次随机选两个点,把两个点之间的全部点,开关都按一遍,问k次过后开着的灯的期望数量: 析:很容易知道,如果一盏灯被按了奇数次,那么它肯定是开 ...

  5. 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 ...

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

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

  7. LightOj_1284 Lights inside 3D Grid

    题目链接 题意: 给一个X * Y * Z 的立方体, 每个单位立方体内都有一盏灯, 初始状态是灭的, 你每次操作如下: 1)选择一个点(x1, y1, z1)     再选择一个点(x2, y2, ...

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

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=2652" style=""& ...

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

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

随机推荐

  1. React-FlipOver-Counter(日历翻页)

    跟窝一起学习鸭~~ //index.js import React from 'react'; import ReactDOM from 'react-dom'; import './index.cs ...

  2. Python2.7下,调用subprocess启动子进程,读取子进程标准输出若干问题

    1:如果调用的子进程也是一个python脚本,则subprocess.Popen中的bufsize=1无效果.也就是说,即使设置了bufsize=1表示进行行缓冲,子进程如果不显示调用sys.stdo ...

  3. ActivityManagerService

    先上类图: 基本类说明和运行框架图中蓝色表示AMS进程,黄色表示app进程.1. 全局调度者在android中,AMS是activity和进程的全局调度者,也就是说系统中载入和准备载入的activit ...

  4. 每天一个linux命令(1): which命令

    0.学习时间: 2014-05-15 which命令用来在PATH指定的路径中查找特定的文件, 并返回第一个找到的结果. 1. 命令格式:  which 文件名 2.命令功能 一般使用which命令来 ...

  5. 【Leetcode堆】数据流中的第K大元素(703)

    题目 设计一个找到数据流中第K大元素的类(class).注意是排序后的第K大元素,不是第K个不同的元素. 你的 KthLargest 类需要一个同时接收整数 k 和整数数组nums 的构造器,它包含数 ...

  6. AtCoder Beginner Contest 084 C - Special Trains

    Special Trains Problem Statement A railroad running from west to east in Atcoder Kingdom is now comp ...

  7. KiCad EDA 镜像目录说明

    KiCad EDA 镜像目录说明 stable/ -- 稳定版安装包. testing/ -- 测试安装包. nightly/ -- 每日编译安装包. 5.1 版本的每日编译包,这个文件夹是重点,如果 ...

  8. iOS 多个精致动画

    iOS 多个精致动画  http://www.cocoachina.com/bbs/read.php?tid=301262 iOS 零碎小知识     http://www.cocoachina.co ...

  9. Python基础:16面向对象概述

    1:在版本2.2 中,Python社区最终统一了类型(type)和类(class),新式类具备更多高级的OOP特性,扮演了一个经典类(旧式类)超集的角色,后者是Python 诞生时所创造的类对象. 2 ...

  10. SSH基本原理

    SSH原理与运用:远程登录 作者: 阮一峰 年12月21日 SSH是每一台Linux电脑的标准配置. 随着Linux设备从电脑逐渐扩展到手机.外设和家用电器,SSH的使用范围也越来越广.不仅程序员离不 ...