【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 ...
随机推荐
- MySQL练习-主外键多表查询
练习: 1.建立表关系: 请创建如下表,并创建相关约束 USE db1; CREATE TABLE class( cid INT AUTO_INCREMENT PRIMARY KEY, caption ...
- 状压dp(B - 炮兵阵地 POJ - 1185 )
题目链接:https://cn.vjudge.net/contest/276236#problem/B 题目大意:略 具体思路:和我的上一篇写状压dp的思路差不多,不过就是这个题相当于上一个题的升级 ...
- Android平台介绍
一.Android平台介绍 什么是智能手机 具有独立的操作系统,独立的运行空间,可以由用户自行安装软件.游戏.导航等第三方应用程序,并可以通过移动通讯网络来实现无线网络接入的手机类型总称. 智能手机操 ...
- 使用qt写的进制转换器
没有使用什么数据结构,直接使用qt自带的进制转换函数, 实时出结果,代码在后面的链接中,由于初学qt,好多不会,代码构造就有点乱 截图如下
- CentOS安装ANT
第1步:下载ant apache-ant-1.9.2-bin.tar.gz http://archive.apache.org/dist/ant/binaries/ 第2步:解压 tar -zxvf ...
- Linux Module框架【转】
转自:http://www.cnblogs.com/LittleHann/p/4558719.html catalog 1. 概述 2. 使用模块 3. 插入和删除模块 4. 自动化与热插拔 5. 版 ...
- linq和ef关于group by取最大值的两种写法
LINQ: var temp = from p in db.jj_Credentials group p by p.ProfessionID into g select new { g.Key, Ma ...
- 运用java反射
Class类 要正确使用Java反射机制就得使用java.lang.Class这个类.它是Java反射机制的起源.当一个类被加载以后,Java虚拟机就会自动产生一个Class对象.通过这个Class对 ...
- Scrapy的【SitemapSpider】的【官网示例】没有name属性
Windows 10家庭中文版,Python 3.6.4,Scrapy 1.5.0, 上午看了Scrapy的Spiders官文,并按照其中的SitemapSpider的示例练习,发现官文的示例存在问题 ...
- Python基础(1):dir(),help()
Python:3.6.4 开始编写Python程序了...可是,某个模块怎么用呢?模块里的函数怎么用呢?...使用本文介绍的dir().help()两个帮助函数可以 获得绝大部分开发所需要的信息! d ...