angry_birds_again_and_again
TimeLimit: 2000 ms Memory Limit: 65536 KiB
ProblemDescription
Theproblems called "Angry Birds" and "Angry Birds Again andAgain" has been solved by many teams in the series of contest in 2011Multi-University Training Contest.
Thistime we focus on the yellow bird called Chuck. Chuck can pick up speed anddistance when tapped.
Youcan assume that before tapped, Chuck flies along the parabola. When tapped, itchanges to fly along the tangent line. The Chuck starts at the coordinates(0, 0). Now you are given the coordinates of the pig (Px, 0), the x-coordinateof the tapping position (Tx) and the initial flying angle of Chuck (α).
∠AOx= α
Pleasecalculate the area surrounded by Chuck’s path and the ground.(The areasurrounded by the solid line O-Tapping position-Pig-O)
Input
Thefirst line contains only one integer T (T is about 1000) indicates the numberof test cases. For each case there are two integers, px tx, and a float numberα.(0 < Tx ≤ Px ≤ 1000, 0 < α < ) .
Output
Oneline for each case specifying the distance rounded to three digits.
SampleInput
1
2 1 1.0
SampleOutput
0.692
Hint
Source
2014年山东省第五届ACM大学生程序设计竞赛
Circle
TimeLimit: 2000 ms Memory Limit: 65536 KiB
ProblemDescription
Youhave been given a circle from 0 to n - 1. If you are currently at x, you willmove to (x - 1) mod n or (x + 1) mod n with equal probability. Now we want toknow the expected number of steps you need to reach x from 0.
Input
Thefirst line contains one integer T — the number of test cases.
Eachof the next T lines contains two integers n, x (0 ≤ x < n ≤ 1000) as wemention above.
Output
Foreach test case. Print a single float number — the expected number of steps youneed to reach x from 0. The figure is accurate to 4 decimal places.
SampleInput
3
3 2
5 4
10 5
SampleOutput
2.0000
4.0000
25.0000
Hint
Source
2014年山东省第五届ACM大学生程序设计竞赛
Colorful Cupcakes
TimeLimit: 2000 ms Memory Limit: 65536 KiB
ProblemDescription
BeaverBindu has N cupcakes. Each cupcake has one of three possible colors. In thisproblem we will represent the colors by uppercase letters \'A\', \'B\', and\'C\'. Two cupcakes of the same color are indistinguishable. You are given aString cupcakes consisting of exactly N characters. Each character in cupcakesgives the color of one of Bindu\'s cupcakes.
Binduhas N friends, sitting around a round table. She wants to give each friend oneof the cupcakes. Moreover, she does not want to give cupcakes of the same colorto any pair of friends who sit next to each other.
LetX be the number of ways in which she can hand out the cupcakes to her friends.As X can be very large, compute and return the value (X modulo1, 000, 000, 007).
Input
Thefirst line contains one integer T(1 ≤ T ≤ 60)—the number of test cases. Each ofthe next T lines contains one string. Each string will contain between 3 and 50characters, inclusive. Each character in the string will be either \'A\',\'B\', or \'C\'.
Output
Foreach test case. Print a single number X — the number of ways in which she canhand out the cupcakes to her friends.
SampleInput
3
ABAB
ABABA
ABABABABABABABABABABABABABABABABABABABABABABABABAB
SampleOutput
2
0
2
Hint
Source
2014年山东省第五届ACM大学生程序设计竞赛
Devour Magic
TimeLimit: 2000 ms Memory Limit: 65536 KiB
ProblemDescription
InWarcraft III, Destroyer is a large flying unit that must consume magic tosustain its mana. Breaking free of the obsidian stone that holds them, thesemonstrous creatures roar into battle, swallowing magic to feed their insatiablehunger as they move between battles and rain destruction down upon their foes.Has Spell Immunity. Attacks land and air units.
The core skill of the Destroyer is socalled Devour Magic, it takes all mana from all units in a area and gives it tothe Destroyer.
Nowto simplify the problem, assume you have n units in a line, all unit start with0 mana and can increase to infinity maximum mana. All unit except the Destroyerhave mana regeneration 1 in per unit time.
TheDestroyer have m instructions t l r, it means, in time t, the Destroyer useDevour Magic on unit from l to r. We give you all m instructions in time order,count how many mana the Destroyer have devour altogether.
Input
Thefirst line contains one integer T, indicating the test case. For each testcase, the first contains two integer n, m(1 ≤ n, m ≤ 10^5). The the next m lineeach line contains a instruction t l r.(1 ≤ t ≤ 10^5, 1 ≤ l ≤ r ≤ n)
Output
Foreach test case, output the conrespornding result.
SampleInput
1
10 5
1 1 10
2 3 10
3 5 10
4 7 10
5 9 10
SampleOutput
30
Hint
Source
2014年山东省第五届ACM大学生程序设计竞赛
Factorial
TimeLimit: 2000 ms Memory Limit: 65536 KiB
ProblemDescription
Homelesserhates mathematics. He cannot even do addition and subtraction, not to mentioncomputing factorial. He asks Cainiao2hao for help. Cainiao2hao is always busysolving more difficult problems. And now, please help Homelesser to computefactorial. If you cannot do it well, Cainiao2hao will think you are as fool asHomelesser.
Input
Thefirst line contains only one integer T (T is about 10) indicates the number oftest cases. For each case there are one integer n (0 ≤ n ≤ 10).
Output
Oneline for each case specifying the factorial of n.
SampleInput
2
4
3
SampleOutput
24
6
Hint
Source
2014年山东省第五届ACM大学生程序设计竞赛
Full Binary Tree
TimeLimit: 2000 ms Memory Limit: 65536 KiB
ProblemDescription
Incomputer science, a binary tree is a tree data structure in which each node hasat most two children. Consider an infinite full binary tree (each node has twochildren except the leaf nodes) defined as follows. For a node labelled v itsleft child will be labelled 2 * v and its right child will be labelled2 * v + 1. The root is labelled as 1.
Youare given n queries of the form i, j. For each query, you have to print thelength of the shortest path between node labelled i and node labelled j.
Input
Firstline contains n(1 ≤ n ≤ 10^5), the number of queries. Each query consists oftwo space separated integers i and j(1 ≤ i, j ≤ 10^9) in one line.
Output
Foreach query, print the required answer in one line.
SampleInput
5
1 2
2 3
4 3
1024 2048
3214567 9998877
SampleOutput
1
2
3
1
44
Hint
Source
2014年山东省第五届ACM大学生程序设计竞赛
Hearthstone II
TimeLimit: 2000 ms Memory Limit: 65536 KiB
ProblemDescription
Thenew season has begun, you have n competitions and m well prepared decks duringthe new season. Each competition you could use any deck you want, but each ofthe decks must be used at least once. Now you wonder how many ways are there toplan the season — to decide for each competition which deck you are going toused. The number can be very huge, mod it with 10^9 + 7.
Input
Theinput file contains several test cases, one line for each case contains twointeger numbers n and m (1 ≤ m ≤ n ≤ 100).
Output
Oneline for each case, output one number — the number of ways.
SampleInput
3 2
100 25
SampleOutput
6
354076161
Hint
Source
2014年山东省第五届ACM大学生程序设计竞赛
Painting Cottages
TimeLimit: 2000 ms Memory Limit: 65536 KiB
ProblemDescription
Thenew cottage settlement is organized near the capital of Flatland. Theconstruction company that is building the settlement has decided to paint somecottages pink and others — light blue. However, they cannot decide which cottagesmust be painted which color. The director of the company claims that thepainting is nice if there is at least one pink cottage, at least one light bluecottage, and it is possible to draw a straight line in such a way that pinkcottages are at one side of the line, and light blue cottages are at the otherside of the line (and no cottage is on the line itself). The main architectobjects that there are several possible nice paintings. Help them to find outhow many different nice paintings are there.
Input
Thefirst line of the input file contains n — the number of the cottages(1 ≤ n ≤ 300). The following n lines contain the coordinates of the cottages —each line contains two integer numbers xi and yi (−10^4 ≤ xi, yi ≤ 10^4).
Output
Outputone integer number — the number of differentnice paintings of the cottages.
SampleInput
4
0 0
1 0
1 1
0 1
SampleOutput
12
Hint
Sample.
Source
2014年山东省第五届ACM大学生程序设计竞赛
Tree
TimeLimit: 10000 ms Memory Limit: 65536 KiB
ProblemDescription
Thereis an rooted weighted tree of n nodes. The root will be always 1. Let\'s definedist(u, v) as the distance from u to v.
Nowyou are been given the distance from the root to all other nodes. You need tocount the number of different trees when all the edge weights are between [l,r]. Two trees A and B are different if and only if there exists an edge (u, v,w) in A but there is no such edge in B.
Input
Thefirst line contains a integer n(1 ≤ n ≤ 10^5), indicating the number of nodesin the tree. The second line contains n-1 integers start from dist(0, 1) todist(0, n-1)(0 ≤ dist(0, i) ≤ 10^9). The next line contains a integerq(1 ≤ q ≤ 10), indicating the number of query you need to answer. The next qlines, each line contains two number l and r(1 ≤ l ≤ r ≤ 10^9) indicating aspecific query.
Output
Foreach query, output the answer in a single line. The number can be very huge,mod it with 10^9 + 7.
SampleInput
4
1 1 2
3
1 1
1 2
2 2
SampleOutput
2
3
0
Hint
Source
2014年山东省第五届ACM大学生程序设计竞赛
Weighted Median
TimeLimit: 2000 ms Memory Limit: 65536 KiB
ProblemDescription
Forn elements x1, x2, ..., xn with positive integer weights w1, w2, ..., wn. Theweighted median is the element xk satisfying
and ,S indicates
Canyou compute the weighted median in O(n) worst-case?
Input
Thereare several test cases. For each case, the first line contains one integern(1 ≤ n ≤ 10^7) — the number of elements in the sequence. The following linecontains n integer numbers xi (0 ≤ xi ≤ 10^9). The last line contains n integernumbers wi (0 < wi < 10^9).
Output
Oneline for each case, print a single integer number— the weighted median of thesequence.
SampleInput
7
10 35 5 10 15 5 20
10 35 5 10 15 5 20
SampleOutput
20
Hint
TheS which indicates the sum of all weights may be exceed a 32-bit integer. If Sis 5, equals2.5.
Source
2014年山东省第五届ACM大学生程序设计竞赛