]]>URAL 1019 A line paintinghttp://www.shnenglu.com/3144046cjc/archive/2009/07/20/90624.htmlChen JiecaoChen JiecaoMon, 20 Jul 2009 07:00:00 GMThttp://www.shnenglu.com/3144046cjc/archive/2009/07/20/90624.htmlhttp://www.shnenglu.com/3144046cjc/comments/90624.htmlhttp://www.shnenglu.com/3144046cjc/archive/2009/07/20/90624.html#Feedback0http://www.shnenglu.com/3144046cjc/comments/commentRss/90624.htmlhttp://www.shnenglu.com/3144046cjc/services/trackbacks/90624.htmlA Line painting
Time Limit: 2.0 second Memory Limit: 16 MB
The segment of numerical axis from 0 to 109
is painted into white color. After that some parts of this segment are
painted into black, then some into white again and so on. In total
there have been made N re-paintings (1 ≤ N ≤ 5000). You are to write a program that finds the longest white open interval after this sequence of re-paintings.
Input
The first line of input contains the only number N. Next N lines contain information about re-paintings. Each of these lines has a form: aibici
where ai and bi are integers, ci is symbol 'b' or 'w', ai, bi, ci are separated by spaces.
This triple of parameters represents repainting of segment from ai to bi into color ci ('w' 鈥?white, 'b' 鈥?black). You may assume that 0 < ai < bi < 109.
Output
Output should contain two numbers x and y (x < y)
divided by space(s). These numbers should define the longest white open
interval. If there are more than one such an interval output should
contain the one with the smallest x.
]]>URAL 1018 A Binary Apple Treehttp://www.shnenglu.com/3144046cjc/archive/2009/07/19/90553.htmlChen JiecaoChen JiecaoSun, 19 Jul 2009 15:02:00 GMThttp://www.shnenglu.com/3144046cjc/archive/2009/07/19/90553.htmlhttp://www.shnenglu.com/3144046cjc/comments/90553.htmlhttp://www.shnenglu.com/3144046cjc/archive/2009/07/19/90553.html#Feedback0http://www.shnenglu.com/3144046cjc/comments/commentRss/90553.htmlhttp://www.shnenglu.com/3144046cjc/services/trackbacks/90553.html
A Binary Apple Tree
Time Limit: 1.0 second Memory Limit: 16 MB
Let's
imagine how apple tree looks in binary computer world. You're right, it
looks just like a binary tree, i.e. any biparous branch splits up to
exactly two new branches. We will enumerate by natural numbers the root
of binary apple tree, points of branching and the ends of twigs. This
way we may distinguish different branches by their ending points. We
will assume that root of tree always is numbered by 1 and all numbers
used for enumerating are numbered in range from 1 to N, where N is the total number of all enumerated points. For instance in the picture below N is equal to 5. Here is an example of an enumerated tree with four branches:
2 5 \ / 3 4 \ / 1
As
you may know it's not convenient to pick an apples from a tree when
there are too much of branches. That's why some of them should be
removed from a tree. But you are interested in removing branches in the
way of minimal loss of apples.
So your are given amounts of apples on a branches and amount of
branches that should be preserved. Your task is to determine how many
apples can remain on a tree after removing of excessive branches.
Input
First line of input contains two numbers: N and Q (1 ≤ Q ≤ N; 1 < N ≤ 100). N denotes the number of enumerated points in a tree. Q denotes amount of branches that should be preserved. Next N−1
lines contains descriptions of branches. Each description consists of a
three integer numbers divided by spaces. The first two of them define
branch by it's ending points. The third number defines the number of
apples on this branch. You may assume that no branch contains more than
30000 apples.
Output
Output should contain the only number 鈥?amount of apples that can be preserved. And don't forget to preserve tree's root ;-)