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 ... 
随机推荐
- vue-cli下配置项目访问ip和服务器ip
			一.配置项目访问ip,让本次代码支持localhost以外的ip地址访问模式:修改里的host配置,代码如下. 修改完记得 "npm run dev"重启服务. 二.在本地架设服务 ... 
- new操作符具体干了什么
			function Func(){ }; var newFunc=new Func (); new共经过了4个阶段 1.创建一个空对象 var obj=new Object(); 2.设置原型链 把 o ... 
- ES6学习笔记(6)----函数的扩展
			参考书<ECMAScript 6入门>http://es6.ruanyifeng.com/ 函数的扩展 函数的默认值 : ES6可以为函数指定默认值 (1)指定默认值的两种方式 a.函数参 ... 
- 新建cordova应用
			使用命令行(本例命令行均使用as或webstrom的命令行),在任意目录输入以下命令新建cordova应用 cordova create capp1 com.cesc.ewater.capp1 其中c ... 
- The Performance Manifesto
			Manifesto For Performance Testing And Engineering We choose to support others in their quest for bet ... 
- Javascript异步编程的常用方法
			Javascript语言的执行环境是"单线程"(single thread).所谓"单线程",就是指一次只能完成一件任务.如果有多个任务,就必须排队,前面一个任 ... 
- codevs 3070 寻找somebody4(水题日常)
			时间限制: 1 s 空间限制: 32000 KB 题目等级 : 黄金 Gold 题目描述 Description 有一天.....sb不见了,有个人要去找他..他发现sb在一个杨辉三角里.. ... 
- SQLite – ORDER 子句
			SQLite - ORDER BY子句 The SQLite ORDER BY子句用于数据按升序或降序排序,基于一个或多个列. 语法: ORDER BY子句的基本语法如下: SELECT column ... 
- Architecture:架构 元素与关系
			http://www.iso-architecture.org/42010/cm/ Systems have architectures. In the Standard, the architect ... 
- 项目中常用的js方法(持续更新)
			<script> var utils = { //时间戳转日期(timestamp:时间戳 默认当前时间) dateFormat: function(timestamp = new Dat ... 
