【CF398B】B. Painting The Wall(期望)
B. Painting The Walltime limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
User ainta decided to paint a wall. The wall consists of n2 tiles, that are arranged in an n × n table. Some tiles are painted, and the others are not. As he wants to paint it beautifully, he will follow the rules below.
- Firstly user ainta looks at the wall. If there is at least one painted cell on each row and at least one painted cell on each column, he stops coloring. Otherwise, he goes to step 2.
- User ainta choose any tile on the wall with uniform probability.
- If the tile he has chosen is not painted, he paints the tile. Otherwise, he ignores it.
- Then he takes a rest for one minute even if he doesn't paint the tile. And then ainta goes to step 1.
However ainta is worried if it would take too much time to finish this work. So he wants to calculate the expected time needed to paint the wall by the method above. Help him find the expected time. You can assume that choosing and painting any tile consumes no time at all.
InputThe first line contains two integers n and m (1 ≤ n ≤ 2·103; 0 ≤ m ≤ min(n2, 2·104)) — the size of the wall and the number of painted cells.
Next m lines goes, each contains two integers ri and ci (1 ≤ ri, ci ≤ n) — the position of the painted cell. It is guaranteed that the positions are all distinct. Consider the rows of the table are numbered from 1 to n. Consider the columns of the table are numbered from 1 to n.
OutputIn a single line print the expected time to paint the wall in minutes. Your answer will be considered correct if it has at most 10 - 4 absolute or relative error.
Examplesinput5 2
2 3
4 1output11.7669491886input2 2
1 1
1 2output2.0000000000input1 1
1 1output0.0000000000
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define Maxn 2010 double f[Maxn][Maxn];
bool h[Maxn],l[Maxn]; int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) h[i]=l[i]=;
for(int i=;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
h[x]=;l[y]=;
}
int hh=,ll=;
for(int i=;i<=n;i++) if(h[i]) hh++;
for(int i=;i<=n;i++) if(l[i]) ll++;
for(int i=n;i>=hh;i--)
for(int j=n;j>=ll;j--)
{
if(i==n&&j==n) f[i][j]=;
else
{
double pi=1.0*i/n,pj=1.0*j/n;
f[i][j]=(pi*pj+(f[i+][j]+)*(-pi)*pj+(f[i][j+]+)*pi*(-pj)+(f[i+][j+]+)*(-pi)*(-pj))/(1.0-pi*pj);
}
}
printf("%.10lf\n",f[hh][ll]);
return ;
}
【CF398B】B. Painting The Wall(期望)的更多相关文章
- Painting The Wall 期望DP Codeforces 398_B
B. Painting The Wall time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #233 (Div. 2)D. Painting The Wall 概率DP
D. Painting The Wall ...
- CF398B Painting The Wall 概率期望
题意:有一个 $n * n$ 的网格,其中 $m$ 个格子上涂了色.每次随机选择一个格子涂色,允许重复涂,求让网格每一行每一列都至少有一个格子涂了色的操作次数期望.题解:,,这种一般都要倒推才行.设$ ...
- codeforces D. Painting The Wall
http://codeforces.com/problemset/problem/399/D 题意:给出n和m,表示在一个n*n的平面上有n*n个方格,其中有m块已经涂色.现在随机选中一块进行涂色(如 ...
- [Codefoeces398B]Painting The Wall(概率DP)
题目大意:一个$n\times n$的棋盘,其中有$m$个格子已经被染色,执行一次染色操作(无论选择的格子是否已被染色)消耗一个单位时间,染色时选中每个格子的概率均等,求使每一行.每一列都存在被染色的 ...
- cf 398B. Painting The Wall
23333,还是不会..%%%http://hzwer.com/6276.html #include <bits/stdc++.h> #define LL long long #defin ...
- 【HDU4391】【块状链表】Paint The Wall
Problem Description As a amateur artist, Xenocide loves painting the wall. The wall can be considere ...
- HDU 4391 Paint The Wall(分块+延迟标记)
Paint The Wall Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 5 Tips for creating good code every day; or how to become a good software developer
Being a good developer is like being any other good professional, it’s all it’s about doing as much ...
随机推荐
- hdu 1254 推箱子(双重bfs)
题目链接 Problem Description 推箱子是一个很经典的游戏.今天我们来玩一个简单版本.在一个M*N的房间里有一个箱子和一个搬运工,搬运工的工作就是把箱子推到指定的位置,注意,搬运工只能 ...
- python概念-常用模块之究竟你是什么鬼
模块: 一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 说白了,就是一个python文件中定义好了类和方法,实现了一些功能,可以被别的python文件所调用 ...
- Ubuntu 设置 sudo 开机自启动项 无需输入密码
如果你想设置一个需要sudo权限执行的开机自启动项,而不需要输入密码,那么你需要把该程序加入 /etc/sudoers 中.要直线这个, 首先执行 sudo visudo ,在文件最后加入下面一行 ...
- NodeJS让前端与后端更友好的分手
学问 最近“上层建筑”在兴起国学热,所以公司几个月前决定开发一款名叫“学问”的有关于国学的app. APP的详情页面还是由web来显现具体内容,有些类似于新闻页,图文混排什么的web是最适 ...
- XSS报警机制(前端防火墙:第二篇)
XSS报警机制(前端防火墙:第二篇) 在第一章结尾的时候我就已经说了,这一章将会更详细的介绍前端防火墙的报警机制及代码.在一章出来后,有人会问为什么不直接防御,而是不防御报警呢.很简单,因为防御的话, ...
- gcc -O0 -O1 -O2 -O3 四级优化选项及每级分别做什么优化【转】
转自:http://blog.csdn.net/qinrenzhi/article/details/78334677 相关博客http://blog.chinaunix.net/uid-2495495 ...
- avalonJS-源码阅读(一)
写angularJS源码阅读系列的时候,写的太垃圾了.一个月后看,真心不忍直视,以后有机会的话得重写.这次写avalonJS,希望能在代码架构层面多些一点,少上源码.多写思路. avalon暴露句柄方 ...
- 【Andorid开发框架学习】之Volley入门
Volley是Android平台上的网络通信库,能使网络通信更快,更简单,更健壮.Volley特别适合数据量不大但是通信频繁的场景.在listView显示图片这方面,使用volley也是比较好的,不必 ...
- vue引入elementUI 报错
在main.js里面引入import 'element-ui/lib/theme-default/index.css'中报错,无法启动项目,这是把package.json里面的webpack改成 1 ...
- JAVA随笔(二)
在函数传参时,double传给int是不行的,反过来可以.参数只能传值.当参数是字符串时,传递的只是串值:但对于数组来说,传递的是管理权,也就是指针 对象变量是对象管理者. cast转型:基本类型与对 ...