CF 1042 E. Vasya and Magic Matrix】的更多相关文章

E. Vasya and Magic Matrix http://codeforces.com/contest/1042/problem/E 题意: 一个n*m的矩阵,每个位置有一个元素,给定一个起点,每次随机往一个小于这个点位置走,走过去的值为欧几里得距离的平方,求期望的值. 分析: 逆推期望. 将所有值取出,按元素大小排序,然后最小的就是0,往所有大于它的转移即可,复杂度n^2,见下方考试代码. 考虑每个点,从所有小于它的元素转移.排序后,维护前缀和,可以做到O(1)转移. $f[i] =…
感觉不会期望. 首先把所有格子按照权值从小到大排一下序,这样一共有$n * m$个元素,每个元素有三个属性$x, y, val$. 下文中的下标均为排序后的下标. 这样子我们就可以推出公式: $f_i = \frac{1}{k}\sum_{j = 1}^{k}(f_j + (x_j - x_i)^2 + (y_j - y_i)^2)$    $($保证$val_j < val_i$并且这样的元素一共有$k$个$)$. 暴力转移是$n^2$的,但是我们可以把这个式子拆开: $f_i = \frac…
大意:给定n*m矩阵, 初始位置(r,c), 每一步随机移动到权值小于当前点的位置, 得分为移动距离的平方, 求得分期望. 直接暴力dp的话复杂度是O(n^4), 把距离平方拆开化简一下, 可以O(n^2logn). #include <iostream> #include <sstream> #include <algorithm> #include <cstdio> #include <math.h> #include <set>…
题目链接 思路分析 看到题目中 \(n,m \leq 1000\) ,故直接考虑 \(O(n^2)\) 级别做法. 我们先把所有的点按照 \(val\) 值从小到大排序,这样的话二维问题变成序列问题. 设 \(f_i\) 表示走到第 \(i\) 个点的价值的期望. 先列出裸的 \(dp\) 方程:(\(Num\) 表示符合条件的点的个数) \[f_i =\frac{1}{Num} \sum_{a_i > a_j}(x_i-x_j)^2+(y_i-y_j)^2+f_j \] 但是这个好像是 \(O…
F. Magic Matrix 题目连接: http://www.codeforces.com/contest/632/problem/F Description You're given a matrix A of size n × n. Let's call the matrix with nonnegative elements magic if it is symmetric (so aij = aji), aii = 0 and aij ≤ max(aik, ajk) for all…
D. Vasya And The Matrix time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the te…
D. Vasya And The Matrix time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the te…
题目链接  Magic Matrix 考虑第三个条件,如果不符合的话说明$a[i][k] < a[i][j]$ 或 $a[j][k] < a[i][j]$ 于是我们把所有的$(a[i][j], i, j)$升序排序,然后检查当前的三元组$(a[i][j], i, j)$的时候, 先确保第一维值小于他的所有三元组$(x, y, z)$中$f[y][z]$已经设置成$1$ 然后看$f[i]$和$f[j]$是否有交集,如果有则说明不符合题意. #include <bits/stdc++.h&g…
D. Vasya And The Matrix time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teache…
Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teacher has constructed! Vasya knows that the matrix consists of n rows and m columns. For each row, he knows the xor (bitwise excluding…