Codeforces 749E: Inversions After Shuffle】的更多相关文章

题目传送门:CF749E. 记一道傻逼计数题. 题意简述: 给一个 \(1\) 到 \(n\) 的排列,随机选取区间 \([l,r]\) 随机打乱区间内的元素,问打乱后的整个序列的逆序数期望. 题解: 下面是代码,复杂度 \(\mathcal{O}(n\log n)\). #include <cstdio> #include <cstring> typedef long long LL; typedef double db; const int MN = 100005; int N…
http://codeforces.com/problemset/problem/749/E (题目链接) 题意 给出一个1~n的排列,从中等概率的选取一个连续段,设其长度为l.对连续段重新进行等概率的全排列,求排列后整个原序列的逆序对的期望个数. Solution 考虑对于每一对数${(a_i,a_j),i<j}$算贡献. 1.连续段包含${a_i,a_j}$ 不妨设${a_i<a_j}$,则只有当排列后${a_j}$再${a_i}$前面才会对答案有贡献(${a_i>a_j}$的情况同…
Inversions After Shuffle time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a permutation of integers from 1 to n. Exactly once you apply the following operation to this permutat…
大意: 给定一个$n$排列, 随机选一个区间, 求将区间随机重排后整个序列的逆序对期望. 考虑对区间$[l,r]$重排后逆序对的变化, 显然只有区间[l,r]内部会发生改变 而长为$k$的随机排列期望逆序为$\frac{k(k-1)}{4}$(证明考虑逆序与顺序对称性) 所以$[l,r]$的贡献即为$inv(1,n)-inv(l,r)+\frac{(r-l+1)(r-l)}{4}$ 所以就转化为求$\sum\limits_{1\le l\le r\le n}inv(l,r)$ 对于逆序对$(x,…
很神奇的一题 看完题解不由惊叹 题意:$n$个神奇宝贝 $a$个普通球 $b$个高级球 普通球抓住$i$神奇宝贝的概率为$u[i]$ 高级球为$p[i]$ 一起用为$u[i]+p[i]-u[i]*p[i]$ 求期望抓到个神奇宝贝个数 $N,a,b\leq2000$ 首先不难想到$O(n^3)$的暴力$DP$ 听说CF的机子可过 我们接下来写如何优化 对于一个凸函数$f(x)$ 我们假设可以通过某种特殊方式获得其的极值和极值点 令$F(x)=f(x)-kx$ 不难发现$F(x)$也是一个凸函数 仍…
  # Name     A Bachgold Problem standard input/output 1 s, 256 MB    x6036 B Parallelogram is Back standard input/output 1 s, 256 MB    x4139 C Voting standard input/output 1 s, 256 MB    x2671 D Leaving Auction standard input/output 2 s, 256 MB    x…
链接: https://codeforces.com/contest/1278/problem/A 题意: Polycarp has built his own web service. Being a modern web service it includes login feature. And that always implies password security problems. Polycarp decided to store the hash of the password…
                                                                E. Infinite Inversions                                                                                          time limit per test 2 seconds                                            …
转自九野:http://blog.csdn.net/qq574857122/article/details/43643135 题目链接:点击打开链接 题意: 给定n ,k 下面n个数表示有一个n的排列, 每次操作等概率翻转一个区间,操作k次. 问: k次操作后逆序数对个数的期望. 思路: dp[i][j]表示 a[i] 在a[j] j前面的概率 初始就是 dp[i][j]  = 1( i < j ) 则对于翻转区间 [i, j], 出现的概率 P = 1 / ( n * (n+1) /2) 并且…
题目:   time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There is an infinite sequence consisting of all positive integers in the increasing order: p = {1, 2, 3, ...}. We performed n swapoper…