您的位置:首页 > 其它

CodeForces Round

2013-09-09 18:10 134 查看

CodeForces Round 199 Div2

完了,这次做扯了,做的时候有点发烧,居然只做出来一道题,差点被绿.

My submissions
View Code

B. Xenia and Spies

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right.

Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the note to one of his neighbours in the row. In other words, if this spy's number is x, he can pass the note to another spy, either x - 1 or x + 1 (if x = 1 or x = n, then the spy has only one neighbour). Also during a step the spy can keep a note and not pass it to anyone.

But nothing is that easy. During m steps Xenia watches some spies attentively. Specifically, during step ti (steps are numbered from 1) Xenia watches spies numbers li, li + 1, li + 2, ..., ri (1 ≤ li ≤ ri ≤ n). Of course, if during some step a spy is watched, he can't do anything: neither give the note nor take it from some other spy. Otherwise, Xenia reveals the spies' cunning plot. Nevertheless, if the spy at the current step keeps the note, Xenia sees nothing suspicious even if she watches him.

You've got s and f. Also, you have the steps during which Xenia watches spies and which spies she is going to watch during each step. Find the best way the spies should act in order to pass the note from spy s to spy f as quickly as possible (in the minimum number of steps).

Input
The first line contains four integers n, m, s and f (1 ≤ n, m ≤ 105; 1 ≤ s, f ≤ n; s ≠ f; n ≥ 2). Each of the following m lines contains three integers ti, li, ri (1 ≤ ti ≤ 109, 1 ≤ li ≤ ri ≤ n). It is guaranteed that t1 < t2 < t3 < ... < tm.

Output
Print k characters in a line: the i-th character in the line must represent the spies' actions on step i. If on step i the spy with the note must pass the note to the spy with a lesser number, the i-th character should equal "L". If on step i the spy with the note must pass it to the spy with a larger number, the i-th character must equal "R". If the spy must keep the note at the i-th step, the i-th character must equal "X".

As a result of applying the printed sequence of actions spy s must pass the note to spy f. The number of printed characters k must be as small as possible. Xenia must not catch the spies passing the note.

If there are miltiple optimal solutions, you can print any of them. It is guaranteed that the answer exists.

Sample test(s)

Input
3 5 1 3
1 1 2
2 2 3
3 3 3
4 1 1
10 1 3

Output
XXRR
题意:有n个间谍站成一排,编号为S的间谍需要将情报传给编号为F的间谍.审讯者会来巡逻m次,时间分别是Ti,每次查看编号从Li到Ri的间谍.此时这些间谍既不能传出情报也不能接受情报.问最少多长时间将情报传给F.在每一秒持有情报的间谍可以选择不动(X),向右传(R),向左传(L),每次操作需要1单位时间.输出耗时最短的一组可行方案.
思路:纯模拟,关键是理解题意.

View Code

C. Cupboard and Balloons

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius r (the cupboard's top) and two walls of height h (the cupboard's sides). The cupboard's depth is r, that is, it looks like a rectangle with base r and height h + r from the sides. The figure below shows what the cupboard looks like (the front view is on the left, the side view is on the right).

View Code

D. Xenia and Dominoes

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

Xenia likes puzzles very much. She is especially fond of the puzzles that consist of domino pieces. Look at the picture that shows one of such puzzles.

View Code

E. Xenia and Tree

time limit per test
5 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

Xenia the programmer has a tree consisting of n nodes. We will consider the tree nodes indexed from 1 to n. We will also consider the first node to be initially painted red, and the other nodes — to be painted blue.

The distance between two tree nodes v and u is the number of edges in the shortest path between v and u.

Xenia needs to learn how to quickly execute queries of two types:

paint a specified blue node in red;

calculate which red node is the closest to the given one and print the shortest distance to the closest red node.

Your task is to write a program which will execute the described queries.

Input
The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of nodes in the tree and the number of queries. Next n - 1 lines contain the tree edges, the i-th line contains a pair of integers ai, bi(1 ≤ ai, bi ≤ n, ai ≠ bi) — an edge of the tree.

Next m lines contain queries. Each query is specified as a pair of integers ti, vi (1 ≤ ti ≤ 2, 1 ≤ vi ≤ n). If ti = 1, then as a reply to the query we need to paint a blue node vi in red. If ti = 2, then we should reply to the query by printing the shortest distance from some red node to node vi.

It is guaranteed that the given graph is a tree and that all queries are correct.

Output
For each second type query print the reply in a single line.

Sample test(s)

Input
5 4
1 2
2 3
2 4
4 5
2 1
2 5
1 2
2 5

Output
0
3
2
题意:有一棵树,初始时编号为1的节点是红色.接下来进行m步操作,将编号为x的节点染成红色或求出x离最近红点的距离.
思路:这题麻烦之处在于数据量太大,一开始我想不断维护一个dis数组,结果惨遭TLE.于是采用另一种方法,用O(1)染色,然后每次查询时bfs一次.这两种都是O(n)级别的更新,不过很明确的一点是红点越多bfs退出的越快.当红点比较多时,每次维护dis数组需要更新的点数为原点延伸出的全蓝路径唱的一半的和,在红点很多时这个数值也可能很大.相比起来此时每次bfs找最短路所经过的节点就会少一点从而可以设一个阈值,当红点数小于这个值时维护dis数组,否则bfs查询最近红点.

View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: