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 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)\):
\]
\]
写出\(f(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 (概率计算)的更多相关文章
- LightOJ 1284 - Lights inside 3D Grid 概率/期望/二项式定理
题意:给你一个长宽高为x,y,z的长方体,里面每个格子放了灯,再给你k次选取任意长方体形状的区块,对其内所有灯开或关操作,初始为关,问亮灯数量的期望值. 题解:首先考虑选取区块的概率,使某个灯在被选取 ...
- LightOJ - 1284 Lights inside 3D Grid —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1284 1284 - Lights inside 3D Grid PDF (English) Statistic ...
- 【非原创】LightOJ - 1284 Lights inside 3D Grid【概率期望】
学习博客: 戳这里 戳这里 戳这里 戳这里 题意: 在一个三维的空间,每个点都有一盏灯,开始全是关的, 现在每次随机选两个点,把两个点之间的全部点,开关都按一遍:问k次过后开着的灯的期望数量: 题解: ...
- LightOJ 1284 Lights inside 3D Grid (数学期望)
题意:在一个三维的空间,每个点都有一盏灯,开始全是关的.现在每次随机选两个点,把两个点之间的全部点,开关都按一遍,问k次过后开着的灯的期望数量: 析:很容易知道,如果一盏灯被按了奇数次,那么它肯定是开 ...
- 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 ...
- Lights inside 3D Grid LightOJ - 1284 (概率dp + 推导)
Lights inside 3D Grid LightOJ - 1284 题意: 在一个三维的空间,每个点都有一盏灯,开始全是关的, 现在每次随机选两个点,把两个点之间的全部点,开关都按一遍:问k次过 ...
- LightOj_1284 Lights inside 3D Grid
题目链接 题意: 给一个X * Y * Z 的立方体, 每个单位立方体内都有一盏灯, 初始状态是灭的, 你每次操作如下: 1)选择一个点(x1, y1, z1) 再选择一个点(x2, y2, ...
- uva 11605 - Lights inside a 3d Grid(概率)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=2652" style=""& ...
- 3D Grid Effect – 使用 CSS3 制作网格动画效果
今天我们想与大家分享一个小的动画概念.这个梦幻般的效果是在马库斯·埃克特的原型应用程序里发现的.实现的基本思路是对网格项目进行 3D 旋转,扩展成全屏,并呈现内容.我们试图模仿应用程序的行为,因此 ...
随机推荐
- jdbc框架-dbutils的简单使用
jdbc框架-dbutils的简单使用 dbutils:是apache组织的一个工具类,jdbc的框架,更方便我们使用 使用步骤: 1.导入jar包(commons-dbutils-1.4.jar) ...
- TCPThree_C杯 Day2
T1 我已经被拉格朗日插值蒙蔽了双眼,变得智障无比. 第一反应就是拉格朗日插值,然后就先放下了它. 模数那么小,指数那么大,这是一套noip模拟题,拉格朗日,你脑袋秀逗了? 无脑暴力20分贼开心. 正 ...
- phpmyadmin误删表后的恢复过程
转自:http://blog.csdn.net/ssrc0604hx/article/details/18717983 话说今天不知道是抽风了还是失魂了,在用phpmyadmin删除测试数据时,竟然将 ...
- SDUT_2502:火星计数法
火星人的计数规则里只有a,b,c,d四个字母,计数规则从小到大是 a,b,c,d,aa,ab,ac,ad,ba,……. 给出来由a,b,c,d四种字母组成的火星数字,算出该数字是第几个(从1开始). ...
- GIT 公钥配置
1.下载git 2.ssh-keygen -t rsa -C "xxx@xxx.com" 3.cd ~/.ssh 4.ls 5.cat id_rsa.pub 或者C:\User\x ...
- Josephus问题Java实现
package com.qingfeng; /** * @author Administrator * 功能:约瑟夫问题: * 设编号分别为:1,2,...,n的n个人围坐一圈. * 约定序号为k(1 ...
- Android Tween和Frame 动画
关于动画的实现,Android提供了Animation,在Android SDK介绍了2种Animation模式: 1. Tween Animation:通过对场景里的对象不断做图像变换(平移.缩放. ...
- idea 启动一直一直build以及勉勉强强的解决方案
周日做了一个密匙解析的功能,在idea的springboot项目的该类上写了个main方法测试,当时一直提示build,没在意,直接打开eclipse上写 今天早上发现 idea启动springboo ...
- 关于python 中的__future__模块
Python的每个新版本都会增加一些新的功能,或者对原来的功能作一些改动.有些改动是不兼容旧版本的,也就是在当前版本运行正常的代码,到下一个版本运行就可能不正常了. 具体说来就是,某个版本中出现了某个 ...
- H3C 命令行编辑功能