##[1001.Average](http://acm.hdu.edu.cn/showproblem.php?pid=5353)
Summary
people are sitting around a circle and every two adjacent people can exchange only on candy. The goal is to find a valid exchange order to make everyone have equal amount of candies (or determine it is impossible). Solution
Find the sum of the candies. If the sum is not a multiple of , such order does not exist.
let be the difference between the candies -th person have and the average candies.
Enumerate 1-st person’s operation: give a candy to 2, receive a candy from 2, do nothing.
Then determine next one’s operation according to the value :
= −1: receive a candy from + 1.
= 0: just do nothing.
= 1: give a candy to + 1.
otherwise, we can not find a valid exchange order.
Time complexity: .
##[1002.Bipartite Graph](http://acm.hdu.edu.cn/showproblem.php?pid=5354) Summary
We are given an undirected graph with vertices and edges. You are to determine for each vertex , after deleting it, whether the graph becomes a bipartite graph. Solution
For every edge , set a time interval , which means the edge is only available from time to time .
Every deletion will make some edges become unavailable at some time points. More specifically, if we delete -th vertex, every edge adjacent to vertex will unavailable at time . Then the number of available time intervals for each edge will be at most 3.
If we know whether the graph is a bipartite graph at a specific time , we also know whether -th vertex satisfy our will.
Solve the problem: You are given an undirected graph with vertices and edges. Each edge will available only in a specific time interval . For every time , you are to determine whether the graph is a bipartite graph.
Let function solve all time from to and is a set of edges which can exist at some time in interval .
Let mid = , for each edge in , assume the interval is :
,, add the edge and check if it forms an odd circle with other edges added before.
, add the edge to set .
, add the edge to set .
otherwise, add the edge to both sets and .
We can use disjoint-set to maintain odd circles. After each , remember to resume the disjoint-set.
How to resume the disjoint-set:
Just union by rank and there is no need to use path compression.
Before every union operation, use a stack to store the state before.
Resuming the disjoint-set is just to restore the state according to the stack.
Time complexity: ##[1003.Cake](http://acm.hdu.edu.cn/showproblem.php?pid=5355) Summary You are given n integers 1, 2, . . . , and an integer . You need to divide the integer into equal sum parts (or determine it is impossible). Solution
If is not divisible by or , it is impossible.
If we have 2 number 1, 2, . . . , 2, we can divide it into equal sum parts easily.
If is large, we can reduce to . If is small, we can use backtracking to find a possible solution or we can construct the solution by hand.
Time complexity: . ##[1004.Deal](http://acm.hdu.edu.cn/showproblem.php?pid=5356) Summary Given are a weighted tree with vertices. There’s an item with weight in -th vertex. The cost for transporting an item with weight from vertex to vertex is multiply the distance from vertex to vertex . Item will be cached in the vertex it passed. You are going to make transportations and make the sum of cost maximum. Each item will be transported from a vertex containing it and closet to the destination. Solution
Each item is independent, so just consider item by item.
For item , the first transportation must be the longest, same as the second transportation and so on.
Using greedy to find the path. Sort all the possible transportations and get the largest .
Time complexity: . ##[1005.Easy Sequence](http://acm.hdu.edu.cn/showproblem.php?pid=5357) Summary You are given a parentheses string. For -th character, you need to find the number valid strings starting with it or ending with it. For -th character, you need to find the number valid substrings containing it. Solution
let be the position of matched parenthese for -th character, be the number of valid substrings starting with -th character, and be the number of valid substrings ending with -th character.
,
assume is ’(’, let be smallest matched parentheses contain and
both and can be computed by using a stack.
Time complexity: . ##[1006.First One](http://acm.hdu.edu.cn/showproblem.php?pid=5358) Summary For a given sequence , , . . . , , we want to find the value of Whrer S(i ,j) is the sum of ,,…, Solution
is the number of bits in the binary representation of .
Consider the contribution of -th bit: if , is added to the answer.
Enumerate -th bit, and use two pointers to maintain the contribution.
Time complexity: . ##[1007.Group](http://acm.hdu.edu.cn/showproblem.php?pid=5359) Summary We are given an directed graph with vertices and edges. You are to determine for each edge ,after deleting it, whether the number of strongly connected components increases. Solution Let us first solve the vertex deleting one:
Find all the strongly connected components, each strongly connected component can be considered independently.
Let is a strongly connected graph, is the reversal graph of (if in then in ), be the flowgraph with start vertex , the set of non-trivial dominators in , be the flowgraph with start vertex , the set of non-trivial dominators in .
Then vertex is a strong articulation point in if and only if .
proving it is not easy, you may google it if you have interest.
Now let us solve the edge deleting one: for each edge , add an extra vertex between the edge, . We can use the mothod above to solve it. Time complexity: ##[1008.Hiking](http://acm.hdu.edu.cn/showproblem.php?pid=5360) Summary There are people and -th people will go out if the number of people going out if no less than and no larger than . You need to invite them one by one to make the number of people going out as large as possible. Solution
sort all the people according to and .
maintain an integer as the number of people agree to go out yet. For all the people will agree to go out, pick the one with smallest .
Time complexity: . ##[1009.In Touch](http://acm.hdu.edu.cn/showproblem.php?pid=5361) Summary vertices are in a straight line and -th vertex is in position . -th vertex can teleport to other vertices whose distance between -th vertex is no less than and no larger than with cost . For each vertex,find the minimum cost from 1-st vertex to it. Solution
let be the cost entering vertex .
use dijkstra to calculate and use disjoint-set to maintain the vertex not visited yet.
the answer is .
Time complexity: . ##[1010.Just A String](http://acm.hdu.edu.cn/showproblem.php?pid=5362) Summary You are given a random string of length and an alphabet of size . You are to tell the expected number of such substrings that can be rearranged to a palindrome in the random string. Solution
The answer is obvious after enumerating the length of the substring:
where is the number of such string with length and alphabet of size .
can be odd or even, let’s solve the even case first:
—— —— ——Let be the generating function for , F(x) be the generating function for . Then and . —— is the coefficient of -th item of , after doing some calculation, we have For a fixed , which can be computed in time.
Now it is time for the odd :
If we precompute the value for then can be computed in time. Time complexity: . ##[1011.Key Set](http://acm.hdu.edu.cn/showproblem.php?pid=5363) Summary For a given set {1, 2, . . . , }, you are to find the number of nonempty subsets with even sum. Solution Let be the number of even integers and be the number of even integers. The answer is: … Time complexity:
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET 9 new features-C#13新的锁类型和语义
· Linux系统下SQL Server数据库镜像配置全流程详解
· 现代计算机视觉入门之:什么是视频
· 你所不知道的 C/C++ 宏知识
· 聊一聊 操作系统蓝屏 c0000102 的故障分析
· DeepSeek V3 两周使用总结
· 回顾我的软件开发经历(1)
· C#使用yield关键字提升迭代性能与效率
· 低成本高可用方案!Linux系统下SQL Server数据库镜像配置全流程详解
· 4. 使用sql查询excel内容
2015-11-22 HDU 2255 奔小康发大财