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 旋转,扩展成全屏,并呈现内容.我们试图模仿应用程序的行为,因此 ...
随机推荐
- python 在init方法中导入数据
- cmakelists.txt中配置openg环境出现: undefined reference to symbol 'glLightfv'
cmakelists.txt中配置openg环境出现: undefined reference to symbol 'glLightfv' 解决方法: 在cmakelists.txt添加 find_p ...
- 【Leetcode链表】移除链表元素(203)
题目 删除链表中等于给定值 val 的所有节点. 示例: 输入: 1->2->6->3->4->5->6, val = 6 输出: 1->2->3-&g ...
- I/O模型: 阻塞、非阻塞、I/O复用、同步、异步
I/O模型不论在实际使用还是准备笔试面试中都是重要的内容,参考Unix网络编程进行总结如下.(尤其注意红色标注处) 1. 明确I/O考察的对象和流程 参考Unix网络编程,一个输入操作通常包括两个不同 ...
- @loj - 2090@ 「ZJOI2016」旅行者
目录 @description@ @solution@ @accepted code@ @details@ @description@ 小 Y 来到了一个新的城市旅行.她发现了这个城市的布局是网格状的 ...
- Header和Cookie相关内容
相信很多同学都对HTTP的header和cookie,和session都有疑问,因为我们开发的时候一般都需要请求网络获取数据,有时候还需要带cookie或者带特殊的字段发起请求. 现在我们就来简单的了 ...
- 1月北上广P2P平台之最 平台数成交量现双降
1月北上广P2P平台之最 平台数成交量现双降 今日(2月9日),网贷之家联合盈灿咨询发布了<北上广地区P2P网贷行业2017年1月月报>.月报数据显示,截至2017年1月底,北京.上海 ...
- day2_python之文件操作
一.文件常用操作 #1. 打开文件的模式有(默认为文本模式): r ,只读模式[默认模式,文件必须存在,不存在则抛出异常] w,只写模式[不可读:不存在则创建:存在则清空内容] a, 之追加写模式[不 ...
- H3C 802.11协议的发展
- Element-ui学习笔记2
1.Button按钮 <el-button> type属性可以修改按钮主题 type='text'时为文字按钮 plain,round,circle可以修改按钮样式,plain为朴素按钮, ...