ACM 2015西安赛区题目

Problem C The Problem Needs 3D Arrays
Description
A permutation is a sequence of integers p1 , p2 , . . . , pn , consisting of n distinct positive
integers and each of them does not exceed n. Assume that r(S) of sequence S denotes the
number of inversions in sequence S (if i < j and Si > Sj , then the pair of (i, j) is called an
inversion of S), l(S) of sequence S denotes the length of sequence S. Given a permutation P
of length n, it’s your task to find a subsequence S of P with maximum r(S)
. A subsequence l(S) of P is a sequence (pi1 , pi2 , . . . , pit ) which satisfies that 0 < i1 < i2 < . . . < it ≤ n.

Input
The first line of the input gives the number of test cases, T. T test cases follow.
For each test case, the first line contains an integer n (1 ≤ n ≤ 100), the length of
the permutation P . The second line contains n integers p1 , p2 , . . . , pn , which represents the
permutation P .
Output
For each test case, output one line containing “Case #x: y”, where x is the test case
number (starting from 1) and y is the maximum r(S)
.
l(S)
Your answer will be considered correct if it is within an absolute error of 10^−6 of the correct
answer.
Samples
Sample Input
1
5
3 4 2 5 1
Sample Output
Case #1: 1.250000000000


Problem D The Diameter of Tree
Description
One day, Little Apple drew a tree on a paper and he wrote down the DFS (depth-first
search) sequence and the BFS (breadth-first search) sequence of the tree. After a few days,
he wants to know the diameter of the tree he drew. Sadly, the paper with the tree is lost. He
can only remember the DFS sequence and the BFS sequence of the tree so that he wants to
know the expected diameter length of the tree. However, he has no idea how to get it. As an
excellent programmer, you are asked for help.
Assume that S is the vertex set of the tree. The distance between two vertices u, v is the
length (in edges) of the shortest path between vertice u and vertice v. The diameter of a tree
is equal to
 max{dist(u, v) | u, v ∈ S}
Here dist(u, v) denotes the distance between two vertices u and v.


Input

The first line of the input gives the number of test cases, T. T test cases follow.
For each test case, the first line contains an integer n (1 ≤ n ≤ 10000), the number of
vertices of the tree. Then two lines follow. The first line contains n integers, which represent
the DFS sequence of the tree. The second line also contains n integers, which represent the
BFS sequence of the tree.
Output
For each test case, output one line containing “Case #x: y”, where x is the test case
number (starting from 1) and y is the expected diameter of the tree.
Your answer will be considered correct if it is within an absolute error of 10−4 of the correct
answer.


Samples

Sample Input
1
7
1 2 3 5 4 7 6
1 2 4 6 3 5 7
Sample Output
Case #1: 4.000


Problem E.  Brushing King
Description
Mr. Big is one of students of Brushing King. He is always sleepy when the course begins.
But Brushing King will punish the students who sleep in the class. In order not to be brushed
by Brushing King, Big wants to know if there is a safe place for him to sleep through the
whole class.
The Brushing King could be considered as a point. His sight is considered as a circular
sector with angle θ and radius R.
Big selected several positions to sleep and he wants to know which one will not be seen by
Brushing King during the course.
Brushing King always walks towards a direction at a speed of 1 and the direction vector of
his movement will be given. He may rotate his sight or his speed direction at some moment.
The course ends right after his last action.
Note that once the position is in the sight of Brushing King (even when Brushing King
just rotates his head), Mr. Big will be caught by Brushing King. Hitting on the edge of the
sight will be also considered as being seen.
Input
The first line of the input gives the number of test cases, T. T test cases follow.
For each test case, the first line contains n, m, θ, R (1 ≤ n, m, R ≤ 1000, 0 < θ < 180)
means the number of position Mr. Big selected and the number of Brushing King’s actions.
The angle will be given in degree.
The second line contains six integers px , py , vx , vy , dx , dy .
(px , py ) is the initial position of Brushing King, (vx , vy ) indicates the initial direction vector
from the initial position of Brushing King to the midpoint of the arc of his sight sector (Note
that it’s NOT guaranteed |(vx , vy )|, |(dx , dy )| equals to 1 or R.). (dx , dy ) is the direction
vector of Brushing King’s movement. (−2000 ≤ px , py ≤ 2000, 1 ≤ |(vx , vy )|, |(dx , dy )| ≤
2000).
Then n lines follow, each of which contains two integers x, y (−2000 ≤ x, y ≤ 2000) means
the coordinate of position selected by Mr.Big.
Then m lines follow, each of which contains three integers, p, t, α (0 ≤ t ≤ 2000, 0 ≤ α ≤
180). There are two types of actions:
1. p = 1 means that at time t, Brushing King rotates the direction vector of his sight
(i.e. the direction vector from his position to the midpoint of the arc of the sight sector)
by α degrees clockwise.
2. p = 2 means that at time t, Brushing King rotates the direction vector of his movement
by α degrees clockwise.
All the t will be given in strictly increasing order. Brushing King’s actions are incredibly
fast and they could be treated as finished in no time.
9The 2014 ACM-ICPC Asia Xi’an Regional Contest
October 26, 2014
Output
For each test case output one line containing “Case #x:”, where x is the test case number
(starting from 1), followed by n numbers, each number is 0 or 1. The i-th number is 1 means
that Mr. Big can survive in i-th position, otherwise 0.

Samples
Sample Input
1
3 2 90 3
0 0 0 1 0 1
50 1
-1 0
-100 0
1 1 180
1 100 0
Sample Output
Case #1: 101



Problem F Color

Description
Recently, Mr. Big recieved n flowers from his fans. He wants to recolor those flowers with
m colors. The flowers are put in a line. It is not allowed to color any adjacent flowers with
the same color. Flowers i and i + 1 are said to be adjacent for every i, 1 ≤ i < n. Mr. Big
also wants the total number of different colors of the n flowers being exactly k.
Two ways are considered different if and only if there is at least one flower being colored
with different colors.
Input
The first line of the input gives the number of test cases, T. T test cases follow. T is about
300 and in most cases k is relatively small.
For each test case, there will be one line, which contains three integers n, m, k (1 ≤ n, m ≤
10^9 , 1 ≤ k ≤ 10^6 , k ≤ n, m).
Output
For each test case, output one line containing “Case #x: y”, where x is the test case
number (starting from 1) and y is the number of ways of different coloring methods modulo
10^9 + 7.


Samples

Sample Input
2
3 2 2
3 2 1
Sample Output
Case #1: 2
Case #2: 0

Problem H The Problem to Make You Happy
Description
Alice and Bob are good friends, as in every other storyline. One day Alice and Bob are
playing an interesting game. The game is played on a directed graph with n vertices and m
edges, Alice and Bob have exactly one chess piece each. Initially, Bob’s chess piece is placed
on vertex x, while Alice’s chess piece is placed at vertex y. Bob plays first, then Alice, then
Bob, then Alice and so on.
During each move, the player must move his/her chess piece from the vertex his/her chess
piece currently at to an adjacent vertex, by traveling through exactly one directed edge.
(Remember that the game is played on a directed graph.) If someone can’t make such a
move, he/she will be considered to lose the game.
There’s one additional rule: at any time, if Bob and Alice’s chess pieces are at the same
vertex, then Alice is consider to be the winner and the game ends up immediately.
Now you are given the initial situation, could you determine who is the winner? Please
note that neither Bob nor Alice will make any mistakes during the game, i.e. they both play
optimally. In case that the game never ends up, Bob is considered to be the winner.
Input
The first line of the input gives the number of test cases, T. T test cases follow.
For each test case, the first line contains two integers n and m (2 ≤ n ≤ 100, 1 ≤
m ≤ n × (n − 1)). Next m lines, each line contains two integers b and e, indicating there
is one directed edge from vertex b to vertex e. Last line contains two integers x and y
(1 ≤ x, y ≤ n, x ̸= y), which are Bob and Alice’s initial position. The graph contains no
self-loops or duplicate edges.
Output
For each test case output one line “Case #x: y”, where x is the case number (starting from
1) and y is “Yes” (without quotes) if Bob can win or the game never ends up, otherwise “No”
(without quotes).
14The 2014 ACM-ICPC Asia Xi’an Regional Contest


Samples

Sample Input
3
5 3
1 2
3 4
4 5
3 1
4 3
1 2
2 3
3 4
1 2
3 3
1 2
2 3
3 1
2 1
Sample Output
Case #1: Yes
Case #2: No
Case #3: Yes


Problem J. Unlimited Battery Works
Description
One day, Little Apple invented a chess game on a rooted tree and he wants to play with
you. At the beginning, there is one and only one black chess piece placed on every vertex of
the tree. In each turn, you can cast a magic on one vertex, which will change the chess piece
on it into white piece whatever it’s white or black before magic. And at the same time, chess
pieces on some vertices will also be changed into white pieces. If you cast a magic on vertex
i, chess piece on vertex j will also be changed into white piece if and only if vertex j is in the
subtree of vertex i and the length (in edges) of the shortest path between i and j is no more
than Ai .
Little Apple wants to know how many steps are neccessary in order to change the tree into
a tree with all chess pieces white. However, as an excellent programmer, you think it’s too
easy for you. You want to calculate the expected steps needed to change all chess pieces on
the tree into white if you choose a vertex to cast a magic randomly (assume that each vertex
has the same probability to be chosen).
Please notice that:
1. If all chess pieces on the tree have been changed into white, you won’t cast magic
anymore.
2. In every turn, it’s possible to choose any vertex of the tree.
Input
The first line of the input gives the number of test cases, T. T test cases follow.
For each test case, the first line contains an integer n (1 ≤ n ≤ 50), the number of vertices
on the tree. The second line contains n integers, which represent A1 , A2 , . . . , An (as described
above, 1 ≤ Ai < 50 for 1 ≤ i ≤ n). The last line conatins n − 1 integers, the i-th integer
represent the parent of vertex i + 1.
It guaranteed that the given graph is a tree and vertex 1 is always the root of the tree.
Output
For each test case, output one line containing “Case #x: y”, where x is the test case
number (starting from 1) and y is the expected steps needed to change all the chess pieces
into white.
Your answer will be considered correct if it is within an absolute error of 10−6 of the correct
answer.


Samples

Sample Input
3
6
1 0 0 0 0 0
1 1 1 1 1
6
1 0 1 0 1 0
1 2 3 4 5
50
0 0 0 0 0 ... 0
0 0 0 0 0... 0
0 0 0 0 0... 0
1 1 1 4 3... 1
13 18 14 15
28 25 28 30
36 37 42 42
Sample Output
Case #1: 6.000000000000
Case #2: 11.000000000000
Case #3: 224.960266916471


Problem K Last Defence
Description
Given two integers A and B. Sequence S is defined as follow:
• S0 = A
• S1 = B
• Si = |Si−1 − Si−2 | for i ≥ 2
Count the number of distinct numbers in S.
Input
The first line of the input gives the number of test cases, T. T test cases follow. T is about
100000.
Each test case consists of one line - two space-separated integers A, B. (0 ≤ A, B ≤ 1018 ).
Output
For each test case, output one line containing “Case #x: y”, where x is the test case
number (starting from 1) and y is the number of distinct numbers in S.


Samples

Sample Input
2
7 4
3 5
Sample Output
Case #1: 6
Case #2: 5
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值