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 金策工业综合大学的更多相关文章

  1. 2016 Al-Baath University Training Camp Contest-1

    2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...

  2. 2015 Multi-University Training Contest 6 solutions BY ZJU(部分解题报告)

    官方解题报告:http://bestcoder.hdu.edu.cn/blog/2015-multi-university-training-contest-6-solutions-by-zju/ 表 ...

  3. 2016 Multi-University Training Contest 10 solutions BY BUPT

    1001. 一个数组上的两个区间求中位数,可以通过分类讨论直接找到中位数,复杂度O(1).不过本题数据较小,优美的log(n)也可过. 1002. 直接求得阴影面积表达式即可. 1003. 二分完成时 ...

  4. 2016 Multi-University Training Contest 8 solutions BY 学军中学

    1001: 假设有4个红球,初始时从左到右标为1,2,3,4.那么肯定存在一种方案,使得最后结束时红球的顺序没有改变,也是1,2,3,4. 那么就可以把同色球都写成若干个不同色球了.所以现在共有n个颜 ...

  5. 2016 Multi-University Training Contest 7 solutions BY SYSU

    Ants 首先求出每个点的最近点. 可以直接对所有点构造kd树,然后在kd树上查询除本身以外的最近点,因为对所有点都求一次,所以不用担心退化. 也可以用分治做,同样是O(NlogN)的复杂度. 方法是 ...

  6. 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}}{ ...

  7. 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)+\ ...

  8. 2016 Multi-University Training Contest 4 solutions BY FZU

    1001 Another Meaning 对于这个问题,显然可以进行DP: 令dp[i]表示到i结尾的字符串可以表示的不同含义数,那么考虑两种转移: 末尾不替换含义:dp[i - 1] 末尾替换含义: ...

  9. 2016 Multi-University Training Contest 3 solutions BY 绍兴一中

    1001 Sqrt Bo 由于有\(5\)次的这个限制,所以尝试寻找分界点. 很容易发现是\(2^{32}\),所以我们先比较输入的数字是否比这个大,然后再暴力开根. 复杂度是\(O(\log\log ...

随机推荐

  1. ES6学习笔记(5)----数值的扩展

    参考书<ECMAScript 6入门>http://es6.ruanyifeng.com/ 数值的扩展 1.Number对象的扩展(1)javascript的全局函数isNaN,isFin ...

  2. Java Web 开发中路径相关问题小结

    Java Web开发中路径问题小结 (1) Web开发中路径的几个基本概念 假设在浏览器中访问了如下的页面,如图1所示: 图1 Eclipse中目录结构如图2所示: 图2 那么针对这个站点的几个基本概 ...

  3. SVN与TFS自动同步脚本(很实用)

    一直都在园子里看文章,因为各种原因懒得写文章.最近稍得空闲,把这几天的工作成果分享一下. 因为工作需要,开发人员使用Qt进行系统移动端的开发,Qt的版本控制却不提供连接TFS的设置,只有使用svn.没 ...

  4. 纯css滚动公告栏目

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  5. android和IOS长连接区别

    http://blog.csdn.net/zhangzeyuaaa/article/details/39028369 首先我们必须知道,所有的推送功能必须有一个客户端和服务器的长连接,因为推送是由服务 ...

  6. strict说明

  7. swift学习——枚举

    swift枚举 1. 枚举基本语法 enum Method { case Add case Sub case Mul case Div } 也可以使用一种更简单的写法 enum Method1{ ca ...

  8. rfcn讲解博客

    http://www.cnblogs.com/lillylin/p/6277094.html ROI pooling操作的输入(对于C+1个类)是k^2*(C+1)*W' *H'(W'和H'是ROI的 ...

  9. COM技术开发(一)

    COM :基本的接口(IX,IY), 组件的实现(CA),以及对组件的调用 #include "pch.h" #include <iostream> #include ...

  10. C-基础:memcpy、memset、memmove、memcmp、memchr

    一,原型 void * memcpy ( void * destination, const void * source, size_t num ); 功能:将以source作为起始地址的数据复制nu ...