Drazil is playing a math game with Varda.
Let's define for positive integer x as a product of factorials of its digits. For example, .
First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:
1. x doesn't contain neither digit 0 nor digit 1.
2. = .
Help friends find such number.
The first line contains an integer n (1?≤?n?≤?15) ― the number of digits in a.
The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
In the first case,
贪心:
首先把原数x计算F(x)后所含有的123456789都统计出来。
然后把9拆成3*3;8拆成2*2*2;6拆成2*3;4拆成2*2;剩下的5和7不能拆,只能直接算阶乘。
最后就剩下了许多个3和许多个2了,此时31定比2少。
最后从大到小顺次输出7,5,3,2便可。
Drazil created a following problem about putting 1?×?2 tiles into an n?×?m grid:
"There is a grid with some cells that are empty and some cells that are occupied. You should use 1?×?2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."
But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".
Drazil found that the constraints for this task may be much larger than for the original task!
Can you solve this new problem?
Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task.
The first line contains two integers n and m (1?≤?n,?m?≤?2000).
The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied.
If there is no solution or the solution is not unique, you should print the string "Not unique".
Otherwise you should print how to cover all empty cells with 1?×?2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example.
In the first case, there are indeed two solutions:
and
so the answer is "Not unique".
然后就开始想怎样快速判断是不是2分图的完全匹配是不是唯1??最后光荣的在第36个数据上T了。。(谁有快速的方法。。求告知vv)
看题解才知道,其实和2分图匹配1点关系都没有。。
有点类似于拓扑排序:能够用同1个纸片覆盖的格子连1条边,把两个格子的度数+1(两个格子之间最多1条边)。
扫描1次所有格子的度数,度数为1的加入队列,那末这些格子所对应的与他们1块被覆盖的格子是唯1的,出队以后把队列中对应格子的对应格子度数⑴,度数为1的再次入队。
如果队列为空以后,所有格子都被覆盖好了,那末此图有且唯一1个解;如果有格子没有被覆盖好,直接输出"Not unique",可能无解,也可能多解(是哪一种就不用管了)
代码中Judge注释掉的部份是暴力用2分图来判定的;输出答案的部份直接用2分图来做了。
Drazil is a monkey. He lives in a circular park. There are n trees around the park. The distance between the i-th tree and (i?+?1)-st trees is di, the distance between the n-th tree and the first tree is dn. The height of the i-th tree is hi.
Drazil starts each day with the morning run. The morning run consists of the following steps:
But there are always children playing around some consecutive trees. Drazil can't stand children, so he can't choose the trees close to children. He even can't stay close to those trees.
If the two trees Drazil chooses are x-th and y-th, we can estimate the energy the morning run takes to him as 2(hx?+?hy)?+?dist(x,?y). Since there are children on exactly one of two arcs connecting x and y, the distance dist(x,?y) between trees x and yis uniquely defined.
Now, you know that on the i-th day children play between ai-th tree and bi-th tree. More formally, if ai?≤?bi, children play around the trees with indices from range [ai,?bi], otherwise they play around the trees with indices from .
Please help Drazil to determine which two trees he should choose in order to consume the most energy (since he wants to become fit and cool-looking monkey) and report the resulting amount of energy for each day.
The first line contains two integer n and m (3?≤?n?≤?105, 1?≤?m?≤?105), denoting number of trees and number of days, respectively.
The second line contains n integers d1,?d2,?...,?dn (1?≤?di?≤?109), the distances between consecutive trees.
The third line contains n integers h1,?h2,?...,?hn (1?≤?hi?≤?109), the heights of trees.
Each of following m lines contains two integers ai and bi (1?≤?ai,?bi?≤?n) describing each new day. There are always at least two different trees Drazil can choose that are not affected by children.
For each day print the answer in a separate line.
首先复制1次,变环为链。
说说我的线段树做法:
对1个区间,保护3个值:
ma: “ |____|”的最大值
L_:“|__”的最大值
_R:“__|”的最大值
然落后行区间合并甚么的就能够了。
题解给出的是RMQ算法:
如果要求x-y这1段的值:(h[y]*2+d[1]+d[2]+d[3]+...d[y⑴])+(h[x]*2-d[1]-d[2]-d[3]-...-d[x⑴])
对第1部份记为A[y],第2部份记为B[x],只要用RMQ求区间最大的A[]和B[]相加便可(可以证明顺序1定不会反过来)
我的线段树代码(1开始数组开到20w会RE...)
定式思惟太可怕。。。