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. poj3262 Protecting the Flowers

    思路: 简单贪心,每次选择性价比最高的. 实现: #include <iostream> #include <cstdio> #include <algorithm> ...

  2. iOS 开发App捕获异常, 反馈给服务器, 提高用户体验

    在我们开发的app中, 不可避免的, 有时候用户使用软件会崩溃.  我们就需要捕获异常, 可以在入口类中加入相应的代码, 可以在每次用户打开程序的时候, 检查一下沙盒中是否有崩溃日志, 如果有, 可以 ...

  3. EEPROM介绍

    EEPROM( Electrically Erasable Programmable Read Only Memory )全称是电气可擦除可编程只读存储器,是非易失存储器,可以访问到每个字节,容量比较 ...

  4. 8 Explicit Animations 指明的动画 笔记

    8 Explicit Animations 指明的动画 笔记     If you want something done right, do it yourself. 如果你想让事情做好,那就自动来 ...

  5. phpstorm中快速添加函数注释

    Preferences 或 command+,快捷键 Live Templates - PHP 下方 - 新建模板 ,Abbreviation 命名随便写,点击Edit Variables配置变量信息 ...

  6. Javaweb之xml

        1 XML概述     1.1 XML是什么? eXtensible Markup Language可扩展标记语言          1.2 XML作用         主要是用于描述数据,而 ...

  7. 北京区域赛I题,Uva7676,A Boring Problem,前缀和差分

    转载自https://blog.csdn.net/weixin_37517391/article/details/83821752 题解 其实这题不难,只要想到了前缀和差分就基本OK了. 我们要求的是 ...

  8. nginx的编译安装

    下载源码 wget http://nginx.org/download/nginx-1.15.9.tar.gz 安装开发包组 yum groupinstall "Development To ...

  9. 16.04 下修改 ssh 默认端口

    打开/etc/ssh/ssh_config,在Port指令下追加新的端口设置: Port 8888 即允许通过端口 8888 进行 ssh 访问. 打开/etc/ssh/sshd_config,进行同 ...

  10. U盘制作安装盘后容量不能恢复的解决方案

    diskpartlist diskselect disk 0/1 --看具体U盘是0还是1clean