【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 ...
随机推荐
- 【译】第六篇 Replication:合并复制-发布
本篇文章是SQL Server Replication系列的第六篇,详细内容请参考原文. 合并复制,类似于事务复制,包括一个发布服务器,一个分发服务器和一个或多个订阅服务器.每一个发布服务器上可以定义 ...
- 【译】第四篇 Integration Services:增量加载-Updating Rows
本篇文章是Integration Services系列的第四篇,详细内容请参考原文. 回顾增量加载记住,在SSIS增量加载有三个使用案例:1.New rows-add rows to the dest ...
- 编写pl/sql时,报错
/* 写一个简单的PL/SQL */ declare a ; b ; c number; begin c:=(a+b)/(a-b); dbms_output.put_line(c); exceptio ...
- 揭秘Patchwork APT攻击-恶意软件样本BADNEWS
1.前言 在2016年左右研究人员发现一个与东南亚和中国南海问题的APT攻击,该APT攻击利用MS Offcie系列漏洞通过钓鱼邮件的形式欺骗受害者点击木马.以美国在内的各国政府和公司为目标发送了大量 ...
- Shell-输入密码转换为*
Code: read -p "请输入使用者都名称:" USER echo -e "请输入使用者密码: \c" while : ;do char=` #这里是反引 ...
- Task多线程进行多进程
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using Sys ...
- NuGet服务器搭建教程
本文主要来自网络,进行整理而成,相关文章如下: http://diaosbook.com/Post/2012/12/15/setup-private-nuget-server https://www. ...
- npm 下载node-zookeeper包
环境:centos7(lunix) 1.安装nvm curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install. ...
- 树莓派指定静态IP
1.备份并清空 interfaces 文件 cp /etc/network/interfaces /etc/network/interfaces.bak vi /etc/network/interfa ...
- AdvStringGrid 垂直居中 、水平居中
官网faq,解答: 结果: