转载请注明出处: ——by fraud
这场的前两题完全是手速题。。。A题写了7分钟,交的时候已经500+了,好在B题出的速度勉强凑活吧,and C题也没有FST
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars.
Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot?
First line of input contains an integer n (2 ≤ n ≤ 105), the number of players.
The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109) — the bids of players.
Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise.
4 75 150 75 50
Yes
3 100 150 250
No
In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal.
A题没啥好说的,把因为可以乘2或乘三,那只要看看除了2和3之外,其他的因子是否相同即可
1 //##################### 2 //Author:fraud 3 //Blog: http://www.cnblogs.com/fraud/ 4 //##################### 5 //#pragma comment(linker, "/STACK:102400000,102400000") 6 #include7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 #include 15 #include
16 #include 17 #include 18 #include 19 #include
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of hi identical blocks. For clarification see picture for the first sample.
Limak will repeat the following operation till everything is destroyed.
Block is called internal if it has all four neighbors, i.e. it has each side (top, left, down and right) adjacent to other block or to the floor. Otherwise, block is boundary. In one operation Limak destroys all boundary blocks. His paws are very fast and he destroys all those blocks at the same time.
Limak is ready to start. You task is to count how many operations will it take him to destroy all towers.
The first line contains single integer n (1 ≤ n ≤ 105).
The second line contains n space-separated integers h1, h2, ..., hn (1 ≤ hi ≤ 109) — sizes of towers.
Print the number of operations needed to destroy all towers.
6 2 1 4 6 2 2
3
7 3 3 3 1 3 3 3
2
The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color.
同样很水,从左到右以及从右到左各扫一遍即可
1 //##################### 2 //Author:fraud 3 //Blog: http://www.cnblogs.com/fraud/ 4 //##################### 5 //#pragma comment(linker, "/STACK:102400000,102400000") 6 #include7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 #include 15 #include
16 #include 17 #include 18 #include 19 #include
Limak is a little bear who learns to draw. People usually start with houses, fences and flowers but why would bears do it? Limak lives in the forest and he decides to draw a tree.
Recall that tree is a connected graph consisting of n vertices and n - 1 edges.
Limak chose a tree with n vertices. He has infinite strip of paper with two parallel rows of dots. Little bear wants to assign vertices of a tree to some n distinct dots on a paper so that edges would intersect only at their endpoints — drawn tree must be planar. Below you can see one of correct drawings for the first sample test.
Is it possible for Limak to draw chosen tree?
The first line contains single integer n (1 ≤ n ≤ 105).
Next n - 1 lines contain description of a tree. i-th of them contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) denoting an edge between vertices ai and bi. It's guaranteed that given description forms a tree.
Print "Yes" (without the quotes) if Limak can draw chosen tree. Otherwise, print "No" (without the quotes).
8 1 2 1 3 1 6 6 4 6 7 6 5 7 8
Yes
13 1 2 1 3 1 4 2 5 2 6 2 7 3 8 3 9 3 10 4 11 4 12 4 13
No
一开始少考虑了一些,然后只是判断儿子不符合的情况,然后还有一些漏考虑的细节。
统计有多少个一定要占一半边的子树,如果超过两个,那就是不符合的。
树形dp,第一次dfs统计好所有子树,第二遍,把根的信息传下来一起考虑就ok了。
1 //##################### 2 //Author:fraud 3 //Blog: http://www.cnblogs.com/fraud/ 4 //##################### 5 //#pragma comment(linker, "/STACK:102400000,102400000") 6 #include7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 #include 15 #include
16 #include 17 #include 18 #include 19 #include