题目链接:https://vjudge.net/problem/LightOJ-1284

1284 - Lights inside 3D Grid
Time Limit: 4 second(s) Memory Limit: 32 MB

You are given a 3D grid, which has dimensions XY 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,

  1. You select a cell A randomly from the grid,
  2. You select a cell B randomly from the grid and
  3. Toggle the states of all the bulbs bounded by cell A and cell B, i.e. make all the ON lights OFF and make all the OFF lights ON which are bounded by A and B. To be clear, consider cell A is (x1, y1, z1) and cell B is (x2, y2, z2). Then you have to toggle all the bulbs in grid cell (x, y, z) where min(x1, x2) ≤ x ≤ max(x1, x2)min(y1, y2) ≤ y ≤ max(y1, y2) and min(z1, z2) ≤ z ≤ max(z1, z2).

Your task is to find the expected number of lights to be ON after K turns.

Input

Input starts with an integer T (≤ 50), denoting the number of test cases.

Each case starts with a line containing four integers X, Y, Z (1 ≤ X, Y, Z ≤ 100) and K (0 ≤ K ≤ 10000).

Output

For each case, print the case number and the expected number of lights that are ON after K turns. Errors less than 10-6 will be ignored.

Sample Input

Output for Sample Input

5

1 2 3 5

1 1 1 1

1 2 3 0

2 3 4 1

2 3 4 2

Case 1: 2.9998713992

Case 2: 1

Case 3: 0

Case 4: 6.375

Case 5: 9.09765625

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = 1e5+; double Get(int pos, int n)
{
return 1.0 - 1.0*((pos-)*(pos-)+(n-pos)*(n-pos))/(n*n);
} double qpow(double x, int y)
{
double s = ;
while(y)
{
if(y&) s *= x;
x *= x;
y >>= ;
}
return s;
} int main()
{
int T, x, y, z, k, kase = ;
scanf("%d", &T);
while(T--)
{
double ans = ;
scanf("%d%d%d%d", &x,&y,&z,&k);
for(int i = ; i<=x; i++)
for(int j = ; j<=y; j++)
for(int t = ; t<=z; t++)
{
double p = Get(i,x)*Get(j,y)*Get(t,z);
ans += 0.5-0.5*qpow(-*p, k);
}
printf("Case %d: %.10lf\n", ++kase, ans);
}
}

LightOJ - 1284 Lights inside 3D Grid —— 期望的更多相关文章

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

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

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

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

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

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

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

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

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

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

  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. DbVisualizer9.0.6破解版下载、破解方法以及补丁

    DbVisualizer破解方法如下:第一步:把下载的dbvis.puk文件,替换掉安装目录“D:\Program Files\DbVisualizer-6.0.12\lib”下dbvis.jar里面 ...

  2. spark-submit提交方式测试Demo

    写一个小小的Demo测试一下Spark提交程序的流程 Maven的pom文件 <properties> <maven.compiler.source>1.7</maven ...

  3. 【Python】matplotlib绘制折线图

    一.绘制简单的折线图 import matplotlib.pyplot as plt squares=[1,4,9,16,25] plt.plot(squares) plt.show() 我们首先导入 ...

  4. SharePoint 2013 对话框

    The quick way to open a sharepoint 2013 dialog modal form is via Javascript below 1 2 3 4 5 function ...

  5. SAS中的自动变量

    Sas自动变量:由数据步语句自动创建的. _n_ :观测序号: _error_:错误信息变量; _numeric_ :所有数值变量: _character_:所有字符变量; _all_:所有变量; f ...

  6. Java中执行存储过程和函数

    装载于:http://www.cnblogs.com/liunanjava/p/4261242.html 一.概述 如果想要执行存储过程,我们应该使用 CallableStatement 接口. Ca ...

  7. EMC机理------串扰

    转:电子工程师不得不知道的EMC机理------串扰(韬略科技EMC) 串扰是信号完整性中最基本的现象之一,在板上走线密度很高时串扰的影响尤其严重.我们知道,线性无缘系统满足叠加定理,如果受害线上有信 ...

  8. CentOS 6.5语言包裁剪

    https://www.ibm.com/developerworks/cn/linux/l-cn-linuxglb/ 浅析 Linux 的国际化与本地化机制 Linux 是一个国际化的操作系统,它的工 ...

  9. 网络虚拟化基础协议之Geneve

    网络虚拟化最基础的技术莫过于分层(Overlay.Underlay),要实现分层有两种手段.一个是映射(Mapping),一个是封装(Encapsulation). 映射,主要思路是转发时替换报文语义 ...

  10. git是一种分布式代码管理工具,git通过树的形式记录文件的更改历史,比如: base'<--base<--A<--A' ^ | --- B<--B' 小米工程师常常需要寻找两个分支最近的分割点,即base.假设git 树是多叉树,请实现一个算法,计算git树上任意两点的最近分割点。 (假设git树节点数为n,用邻接矩阵的形式表示git树:字符串数组matrix包含n个字符串,每个字符串由字符'0

    // ConsoleApplication10.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream& ...