2016 Multi-University Training Contest 9 solutions BY 金策工业综合大学
A Poor King
Tag: Reversed BFS
Preprocessing is needed to calculate answers for all positions (states). Beginning with all checkmate states, you should do reversed Breath-First Search (BFS) to update values. The state can be specified by three positions, so 646464 states in all. For each state, make all possible next states and check if all their values had already determined. If so, you can determine the value (answer) for this state.
Best Division
Tag: DP, Trie, Data structure
This is a Dynamic Programming (DP) problem. Let dp[i] be the answer (maximum K) for the subarray A[1]~A[i]. Then, dp[i] = (max i-L≤j<i, S[i]^S[j]≤X dp[j]) + 1 (S[i] = A[1]^A[2]^…^A[i]). Now, build bit (1-0) trie to add S[i] values in order. For each i, indices such that S[i]^S[j]≤X is determined by going down along the trie, considering X. Maximum values of a subtree can be stored in its root. Adding or removing values to/from the trie can be done by suitable data structure such as sliding RMQ or multiset.
Convex Hull
Tag: Geometry, 3D transform, Convex hull
Several geometric procedures are needed to solve this problem. First, construct the 3D convex hull of given points. Then, for each query, use CG formulas to transform the query plane to XOY plane. After that, you can find out all intersection points between the edges of convex hull and XOY plane. Now, answer is the area of 2D convex hull of these points.
Different Sums
Tag: Construction, Math
For small n, it’s easy problem.
Let S[i] be the sum of first i numbers.
We take a prime number p larger than n, and an integer x (0 <= x < p), make S[i] = 2 * i * p + (i * (i+1) / 2 * x) % p. Let’s define r[i] = (i * (i+1) / 2 * x) % p.
If S[i] – S[j] = S[k] – S[l], then i – j = k – l because |r[i] -r[j]| < p and |r[k] – r[l]| < p. Also (r[i] – r[j] – r[k] + r[l]) must be divisible by p, this leads to i + j = k + l. It means that i = k and j = l.
Thus, the array that has these subsums satisfies the problem statement.
Now we must make all integers in the array less than 3n+18.
We can choose p as the smallest prime larger than n, and select x that minimizes max{S[i]-S[i-1]}.
For all 6 <= n <= 2000, if we choose x optimally, the maximum value of S[i]-S[i-1] is less than 3n+18.
Easy Homework
Tag: Number theory, Baby-step giant-step algorithm
A simple identity f(n+1) * f(n-1) – f(n) * f(n) = (-1) ^ n holds for all integers n.
Assume that f(n)=x, f(n-1)=y, then a quadratic modular congruence (Ax+y)y –x *x = (-1) ^ n holds.
Thus, the number of different pairs (x, y) is O(p) for modulo p, so the period must be O(p). Also for given x, there are at most four different y values. All y candidates can be calculated by Shanks-Tonelli algorithm. Now, you pre-calculate sqrt(p) pairs and check whether (x, y) pair appears using baby-step giant-step algorithm. By doing so, the period can be computed in O(sqrt(p)) steps and the total time complexity is O(sqrt(p)), the problem can be solved.
Flight
Tag: Data structure, RMQ
We can easily find out the answer for each query can be an integer from -1 to 3.
First find the diameter D of the given tree. Let’s assume that its two end nodes are U and V. From now, U is the root of the tree, and the path from U to V will be marked. Let’s denote f(u) as the nearest marked node from u.
Determining the possibility in two steps is the most important part.
This will be determined by min{dist(U, u) , dist(U, v)}>=d or min{dist(V, u) , dist(V, v)}>=d, or there exists at least one node w, f(w) is on the path from f(u) to f(v)), min{dist(w, u), dist(w, v)} >= d. The last condition can be checked by considering the center c of the path from u to v. So for all nodes w, if f(w) is on the path f(u) to f(c), dist(u, w) >=d, else dist(v, w) >=d must be held. This leads a simple range maximum query problem. These can be pre-calculated, so we can answer each query by O(1) time. So required time is O(N*log(N)+Q).
Generator
Tag: Inclusion/Exclusion principle, String Matching, Linear equations.
Consider the probability that all sequences are generated in i seconds. Let’s denote it as f(i). The answer is the sum of i(f(i)-f(i-1)) for all positive integers i. By inclusion/exclusion principle, f(i) is the signed sum of the probability of 2^N subsets of sequences are not generated in i seconds. For each subset S, let’s denote it as p(S, i). Then q(S,i) = 1-p(S,i) is the probability which at least a sequence of S is generated in i seconds. So f(i) is the signed sum of q(S,i), for all non-empty subset of {1,2,…,N}. The sign is +1 for odd subset, -1 for even subset. For a fixed subset S, summing i(q(S, i)-q(S,i-1)) for all integer i, it’s simply the expected time of at least a sequence of S is generated. Let’s denote it as e(S). So the answer is the signed sum of all e(S).
e(S) can be calculated by linear equation.
Let x(i) will be the probability i-th sequence of S is the first generated.
Then sum of all x(i) equals to 1. And there are |S| equations about x(i) and e(S). All coefficients are calculated by KMP matching. So the answer can be calculated by O(NNL+NNN*2^N).
Honey Tour
Tag: Plug DP, Matrix exponentiation
Cells on a path have exactly two adjacent on-path cells except the two ends.
Combine connected component id and cell’s degree to represent DP state.
The number of valid states Ns is less than 200.
Calculate state transition matrix by passing the maze once.
Intersection is not allowed!
Tag: Counting, Matrix
For the simplest case, if K = 1, the number of different ways from (1, a1) to (N, b1) is . Here, means binomial coefficient.
If K = 2, the answer is the product of two independent numbers of ways minus number of intersecting ways. Here, all intersecting ways correspond to the ways from (1, a1) to (N, b2) and from (1, a2) to (N, b1). Thus, the answer is
\(C_{(b_1-a_1)+(N-1)}^{N-1} \times C_{(b_2-a_2)+(N-1)}^{N-1}-C_{(b_2-a_1)+(N-1)}^{N-1} \times C_{(b_1-a_2)+(N-1)}^{N-1}\)
\(= \begin{vmatrix} C_{(b_1-a_1)+(N-1)}^{N-1} & C_{(b_2-a_2)+(N-1)}^{N-1}\\ C_{(b_1-a_2)+(N-1)}^{N-1} & C_{(b_2-a_1)+(N-1)}^{N-1} \end{vmatrix}\)
Let \(f(i,j) = C_{(b_j-a_i)}^{N-1}\)be the number of ways from (1, ai) to (N, bj).
In general, it can be proved that the answer is represented as the following determinant:
\(|f(i,j)_{K*K}| =\begin{vmatrix}C_{(b_1-a_1)+(N-1)}^{N-1} &\cdots &C_{(b_K-a_2)+(N-1)}^{N-1}\\\cdots & \cdots & \cdots \\C_{(b_1-a_K)+(N-1)}^{N-1} & \cdots & C_{(b_K-a_K)+(N-1)}^{N-1}\end{vmatrix}\)
Jong Hyok and String
Tag: Suffix automata
Suffix Automaton’s each node has corresponding set of strings related to it.
Strings in this set have common occurrences in the given strings P1, …, PN.
Therefore, your task is to count the number of strings related to the SAM node related to string qi.
This can be done by calculating len[u]-len[link[u]].
K-th Value
Tag: Binary search
Binary search for Ans.
Root the tree at an arbitrary node.
We define f(i, l) as the maximum number of edges whose length isn’t bigger than Ans of any downward path starting from i and with length l.
And define g(i, l) = k * f(i, l) – l.
If there exists a pair (i, l) with L <= l <= R and g(i, l) > 0, then return true.
Otherwise if there exists two pairs (i, l) and (j, h) with L <= l + h <= R and parent(i) = parent(j) and g(i, l) + g(j, h) > 0 return true.
This could take NR time using sweeping.
Otherwise return false.
So the time complexity is N * R * logN.
Less Time, More Profit
Tag: Binary search, Maximum flow
Find the minimum time by using binary search. Let’s see time tm is valid!
Make the graph G(V, E, C). V: nodes, E: edges C: value of nodes
V: = X + Y, X = {1, 2, …, N} , Y = {1, 2, … M}
E: (v, u), , we need u to enable v.
C: c[v] = pro[v]
Calculate maximum weight closure of G by using maximum flow.
When this value is not less than L, tm is valid.
Math is Fun
Tag: DP, State compression, Inclusion-exclusion principle
For every integer g, calculate the GLL value of the subset consists of multiples of g in A. This is done by DP-like approach. Represent LCMs as its prime factorization state. Use map (or unordered_map) to hash states. When adding a number, update map with original states and new states which is LCM of original state and a new number. For branching and bounding, primes that do not appear further should be removed to compress and merge states. This method makes it possible to calculate the sum of LCM (or LCM^2) very quickly. Finally, compute the answer from GLL of many g values, by using inclusion-exclusion principle.
2016 Multi-University Training Contest 9 solutions BY 金策工业综合大学的更多相关文章
- 2016 Al-Baath University Training Camp Contest-1
2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...
- 2015 Multi-University Training Contest 6 solutions BY ZJU(部分解题报告)
官方解题报告:http://bestcoder.hdu.edu.cn/blog/2015-multi-university-training-contest-6-solutions-by-zju/ 表 ...
- 2016 Multi-University Training Contest 10 solutions BY BUPT
1001. 一个数组上的两个区间求中位数,可以通过分类讨论直接找到中位数,复杂度O(1).不过本题数据较小,优美的log(n)也可过. 1002. 直接求得阴影面积表达式即可. 1003. 二分完成时 ...
- 2016 Multi-University Training Contest 8 solutions BY 学军中学
1001: 假设有4个红球,初始时从左到右标为1,2,3,4.那么肯定存在一种方案,使得最后结束时红球的顺序没有改变,也是1,2,3,4. 那么就可以把同色球都写成若干个不同色球了.所以现在共有n个颜 ...
- 2016 Multi-University Training Contest 7 solutions BY SYSU
Ants 首先求出每个点的最近点. 可以直接对所有点构造kd树,然后在kd树上查询除本身以外的最近点,因为对所有点都求一次,所以不用担心退化. 也可以用分治做,同样是O(NlogN)的复杂度. 方法是 ...
- 2016 Multi-University Training Contest 6 solutions BY UESTC
A Boring Question \[\sum_{0\leq k_{1},k_{2},\cdots k_{m}\leq n}\prod_{1\leq j< m}\binom{k_{j+1}}{ ...
- 2016 Multi-University Training Contest 5 solutions BY ZSTU
ATM Mechine E(i,j):存款的范围是[0,i],还可以被警告j次的期望值. E(i,j) = \(max_{k=1}^{i}{\frac{i-k+1}{i+1} * E(i-k,j)+\ ...
- 2016 Multi-University Training Contest 4 solutions BY FZU
1001 Another Meaning 对于这个问题,显然可以进行DP: 令dp[i]表示到i结尾的字符串可以表示的不同含义数,那么考虑两种转移: 末尾不替换含义:dp[i - 1] 末尾替换含义: ...
- 2016 Multi-University Training Contest 3 solutions BY 绍兴一中
1001 Sqrt Bo 由于有\(5\)次的这个限制,所以尝试寻找分界点. 很容易发现是\(2^{32}\),所以我们先比较输入的数字是否比这个大,然后再暴力开根. 复杂度是\(O(\log\log ...
随机推荐
- 回顾PMP考试
2014年9月20日,于我来说绝对可以说是一个重要的日子.经过考场里4个多小时(4个小时正式的时间+前面的签到以及后面的survey等)的鏖战,出去之后才发现北京外国语大学的楼宇是如此的漂亮,阳光也是 ...
- http接口调用,传递json格式带双引号问题
springmvc 配置好会自动转换json格式,只要配置他转格式之前,在转次String类型就好
- 洛谷 P1507 NASA的食物计划
题目背景 NASA(美国航空航天局)因为航天飞机的隔热瓦等其他安 全技术问题一直大伤脑筋,因此在各方压力下终止了航天 飞机的历史,但是此类事情会不会在以后发生,谁也无法 保证,在遇到这类航天问题时,解 ...
- TensorFlow低阶API(四)—— 图和会话
简介 TensorFlow使用数据流图将计算表示为独立的指令之间的依赖关系.这可生成低级别的编程模型,在该模型中,您首先定义数据流图,然后创建TensorFlow会话,以便在一组本地和远程设备上运行图 ...
- socks5代理原理解析
sock5代理的工作程序是: 1.需要代理方向服务器发出请求信息. 2.代理方应答 3.需要代理方接到应答后发送向代理方发送目的ip和端口 4.代理方与 ...
- 自己写的画loss曲线代码
import matplotlib.pyplot as plt iteration = [] loss = [] with open('/home/sensetime/log.txt','r') as ...
- Vickers Vane Pump Tips - Vane Pump Maintenance Note
The Vickers Vane Pump describes the matters needing attention in the maintenance of the vane p ...
- windows10用WMware安装Linux虚拟机详细步骤
windows10用WMware安装Linux虚拟机详细步骤 一.安装环境 windows10操作系统物理机VMware Workstation 软件(可以在网上下载)CentOS6.9镜像文件( ...
- VR技术在数据中心3D机房中的应用 (下)
VR技术在数据中心3D机房中的应用 (下) 前面给大家简单科普了一下VR的硬件设备以及VR在各个领域的应用,是不是觉得非常高大上?千言万语概括成一句话,VR能给用户带来前所未有的沉浸感和交互方式,让人 ...
- luogu P1238 走迷宫--DFS模板好(水)题
题目描述 有一个m*n格的迷宫(表示有m行.n列),其中有可走的也有不可走的,如果用1表示可以走,0表示不可以走,文件读入这m*n个数据和起始点.结束点(起始点和结束点都是用两个数据来描述的,分别表示 ...