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...)
定式思惟太可怕。。。