题目链接: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. 怎样mac上安装apk到连接数据线的手机

    高大上的mac俺也用了一段时间了.不知道大家有木有同一个烦恼.曾经在win上的时候仅仅要安装了应用宝之类的手机助手.就能够双击APK,直接安装到连接数据线的手机上,非常方便哈,可是mac上不行.近期找 ...

  2. python 查询,子查询以及1对多查询

    1.添加数据: # 方法1:对象.save() book = Book(**kwargs) book.save() # 方法2:类.create(**kwargs) Book.create(**kwa ...

  3. angular 视频教程

    在网上找了一些,视频教程.存在备用 angular 视频教程 百度云盘地址 小时前 1小时前 30 6 angular 4.0视频教程 链接:https://pan.baidu.com/s/1qXIt ...

  4. ZF-net

    ZF-net 摘要: 1.这篇文章的motivation 是 :CNN性能良好,可是我们不知道它为何性能良好.也不知道它怎么能够被提高? 2.本文介绍了一种新方法实现中间层和分类器的可视化 3.採用消 ...

  5. 『HTML5梦幻之旅』 - 仿Qt演示样例Drag and Drop Robot(换装机器人)

    起源 在Qt的演示样例中看到了一个有趣的demo.截图例如以下: 这个demo的名字叫Drag and Drop Robot,简单概括而言,在这个demo中,能够把机器人四周的颜色拖动到机器人的各个部 ...

  6. mapreduce_template

    Hadoop Tutorial - YDN https://developer.yahoo.com/hadoop/tutorial/module4.html import java.io.IOExce ...

  7. 搭建SpringMVC+Hibernate4+Spring3+Ajax+Maven项目

    首先新建一个Maven项目.百度一下会有非常多实例,这里就不介绍了,直接奔主题. 如题:这里使用的是Hibernate4和Spring3,使用的JPA和Spring注解,然后JDK版本号是1.7 以下 ...

  8. 聊聊高并发(三十九)解析java.util.concurrent各个组件(十五) 理解ExecutorService接口的设计

    上一篇讲了Executor接口的设计,目的是将任务的运行和任务的提交解耦.能够隐藏任务的运行策略.这篇说说ExecutorService接口.它扩展了Executor接口,对Executor的生命周期 ...

  9. android开发系列之ContentObserver

    在这篇博客里面我想要分享一下自己最近在项目里面遇到一个比较好的数据同步解决方案,首先让我们先来看看该方案的应用场景:我们在客户端本地利用数据库缓存了一些数据,当我们检测到数据库里面的数据发生变化的时候 ...

  10. JavaWeb、J2-SE开发框架——Spring

    相关博客:   2.spring官网 1.使用Spring的jdbcTemplate进一步简化JDBC操作