LightOj_1284 Lights inside 3D Grid
题意:
给一个X * Y * Z 的立方体, 每个单位立方体内都有一盏灯, 初始状态是灭的, 你每次操作如下:
1)选择一个点(x1, y1, z1)
再选择一个点(x2, y2, z2)
将这两个点所形成的立方体内所有的灯全部转换状态(灭的变亮的, 亮的变灭的)
问, K次操作后, 亮着的灯的期望数目。
思路:
三维坐标系, 每个维度都是相互独立的, 所以可以分开计算再相乘。
考虑x轴, 对于每个点, 被选中的概率是多少:假设这个点左边有a个点,右边有b个点,
那么这个点不被选中的概率是p = 1.0 - ((x - 1) * (x - 1) - (a * a + b * b)) / x * x。
则,这个点在K次操作后被点亮的期望为:E = sigma C(k, i) * p * (1 - p) ^ (k - i),i为奇数, 因为i为偶数时灯是灭的。
这是二项展开式(p + (1 - p)) ^ k 的所有奇数项。
因此, E = ((p + (1 - p)) ^ k - (-p + (1 - p)) ^ k) / 2, 蓝色部分将所有的奇数项变成了负数, 偶数项不变, 相减后则成了两倍的奇数项之和。
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-6
#define MAXN 1000000
#define dd cout<<"debug"<<endl
#define p(x) cout<<x<<endl
int x, y, z, k;
double qpow(double x, int k)
{
double res = 1.0;
while(k)
{
if(k & ) res = res * x;
x = x * x;
k >>= ;
}
return res;
}
double get_p(int x, int n)
{
return 1.0 - ((x - ) * (x - ) * 1.0 + (n - x) * (n - x) * 1.0) * 1.0 / (n * n);
} int main()
{
int T;
int kcase = ;
scanf("%d", &T);
while(T --)
{
double ans = 0.0;
scanf("%d %d %d %d", &x, &y, &z, &k);
for(int i = ; i <= x; i ++)
for(int j = ; j <= y; j ++)
for(int g = ; g <= z; g ++)
{
double p = get_p(i, x) * get_p(j, y) * get_p(g, z);
ans += (1.0 - qpow( - 2.0 * p, k)) / 2.0;
}
printf("Case %d: %.7lf\n", ++kcase, ans);
}
return ;
}
LightOj_1284 Lights inside 3D Grid的更多相关文章
- Lights inside 3D Grid LightOJ - 1284 (概率dp + 推导)
Lights inside 3D Grid LightOJ - 1284 题意: 在一个三维的空间,每个点都有一盏灯,开始全是关的, 现在每次随机选两个点,把两个点之间的全部点,开关都按一遍:问k次过 ...
- LightOJ - 1284 Lights inside 3D Grid —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1284 1284 - Lights inside 3D Grid PDF (English) Statistic ...
- 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 ...
- 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 ...
- LightOJ 1284 - Lights inside 3D Grid 概率/期望/二项式定理
题意:给你一个长宽高为x,y,z的长方体,里面每个格子放了灯,再给你k次选取任意长方体形状的区块,对其内所有灯开或关操作,初始为关,问亮灯数量的期望值. 题解:首先考虑选取区块的概率,使某个灯在被选取 ...
- LightOJ 1284 Lights inside 3D Grid (数学期望)
题意:在一个三维的空间,每个点都有一盏灯,开始全是关的.现在每次随机选两个点,把两个点之间的全部点,开关都按一遍,问k次过后开着的灯的期望数量: 析:很容易知道,如果一盏灯被按了奇数次,那么它肯定是开 ...
- 【非原创】LightOJ - 1284 Lights inside 3D Grid【概率期望】
学习博客: 戳这里 戳这里 戳这里 戳这里 题意: 在一个三维的空间,每个点都有一盏灯,开始全是关的, 现在每次随机选两个点,把两个点之间的全部点,开关都按一遍:问k次过后开着的灯的期望数量: 题解: ...
- uva 11605 - Lights inside a 3d Grid(概率)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=2652" style=""& ...
- 3D Grid Effect – 使用 CSS3 制作网格动画效果
今天我们想与大家分享一个小的动画概念.这个梦幻般的效果是在马库斯·埃克特的原型应用程序里发现的.实现的基本思路是对网格项目进行 3D 旋转,扩展成全屏,并呈现内容.我们试图模仿应用程序的行为,因此 ...
随机推荐
- 导入一个AndroidStudio工程作为一个Library Module
尊重劳动成果,转载请注明出处:http://blog.csdn.net/growth58/article/details/47441245 关注新浪微博:@于卫国 邮箱:yuweiguocn@gmai ...
- hdu2002
import java.util.*;class Main{public static void main(String args[]){Scanner cin=new Scanner(System. ...
- 看懂下面C++代码才说你理解了C++多态虚函数!
#include <iostream> using namespace std ; class Father { private : virtual void Say() //只有添加 ...
- VS2010项目转化为VS2008项目
第一步: 打开VS2010项目的SLN文件有如下代码: Microsoft Visual Studio Solution File, Format Version 11.00# Visual Stud ...
- h5宣传页制作过程中遇到的问题
音乐播放 ios下关闭不流畅; (ios下需重新image 模拟) 音乐设置自动播放属性后 部分机型下不能自动播放.目前解决方案: touchstart时触发播放 微信“分享给朋友”点击发送后,页面卡 ...
- ubuntu15.10下sublime text3 无法输入中文解决办法
原文链接:http://geek.csdn.net/news/detail/44464 1.首先保证你的电脑有c++编译环境 如果没有,通过以下指令安装 sudo apt-get install bu ...
- quartz简单实现
quartz介绍 在我们的项目中,经常会遇到某个任务需要在特定的时间点执行,这个时间点可能是每天的某分某秒,可能是一周的指定某个星期某个时间等:quartz就是实现这样一个复杂任务调度逻辑的框架. 官 ...
- java 开发基础篇1环境安装--eclipse安装教程
如何安装java环境 http://jingyan.baidu.com/article/a24b33cd59b58e19fe002bb9.html JDK download http://www.or ...
- [Mime] MimeEntity--MimeEntity Mime实体帮助类 (转载)
点击下载 MimeEntity.rar 这个类是关于Mime实体的类看下面代码吧 /// <summary> /// 类说明:Assistant /// 编 码 人:苏飞 /// 联系方式 ...
- CI 自动操作日志
在控制器中,继承一个总控制器,MY_Controller,让其他集成的控制器,继承my控制器 在MY_Controller控制器中,重写构造方法, 代码如下,测试pass! class MY_Cont ...