Sie sind auf Seite 1von 4

P3G

1) Clique
A bunch of people on Facebook would like to find
out the largest clique among them.
(Maybe this will be the next facebook
application?).
A clique is defined as a group of people
where everyone is friends with everyone
else.
Given a list of friends (friendship works
both ways), your job is to output the size
of this clique.
For the sake of privacy (and your
convenience), we have replaced the names of
the people with numbers.
Input
Number of people, 1 N 32
Number of friendships, 1 M N*(N-1)/2
M lines, each with 2 numbers 1 a, b N meaning that a and b are friends.
There will be no duplicate edges.
NOTE: 50% of test cases will have N 24.

Output
The size of the maximum clique.

Sample Input
6
2
2
2
3
3
4
5

7
3
4
5
4
5
5
6

Sample Output
4
Friends 2,3,4,5 form the largest clique.

2) Geometric Sequence
A sequence of integers is called a geometric sequence if the ratio of consecutive numbers
is constant.
For example, (3,6,12,24) is a geometric sequence (each term is equal to twice the
previous number)
Now, with such a sequence, we will shuffle it around and remove some of the elements.
Given the result of such a transformation, try to recover the "geometric ratio" of the
original sequence.
If there are multiple values, output the one with the greatest absolute value (if there's still
a tie, output the positive one)
If there is no such sequence, output 0.

Input
The number of integers, 2 N 100,000
N lines, each with one non-zero integer x ( |x| 10^18 )

Output
The ratio of the original sequence (if one exists).
The relative error of the answer must be within 10^-9. ( |answer - expected| / |expected| <
10^-9 )

Sample Input
3
1 3 27

Sample Output
3
The original sequence could have been 1,3,9,27 or 27,9,3,1; the former
has the greater ratio.

3) Dominoes
Farmer John's son, Johnny is playing with some dominoes one afternoon.
His dominoes come in a variety of heights and colors.

Just like any other child, he likes to put them in a row and knock them over.
He wants to know something: how many pushes does it take to knock down all the
dominoes?
Johnny is lazy, so he wants to minimize the number of pushes he takes.
A domino, once knocked over, will knock over any domino that it touches on the way
down.
For the sake of simplicity, imagine the floor as a one-dimensional line, where 1 is the
leftmost point. Dominoes will not slip along the floor once toppled. Also, dominoes do
have some width: a domino of length 1 at position 1 can knock over a domino at position
2.
For the mathematically minded:
A domino at position x with height h, once pushed to the right, will knock all dominoes at
positions x+1, x+2, ..., x+h rightward as well.
Conversely, the same domino pushed to the left will knock all dominoes at positions x-1,
x-2, ..., x-h leftward.

Input
The input starts with a single integer N 100,000, the number of dominoes, followed by
N pairs of integers.
Each pair of integers represents the location and height of a domino.
(1 location 1,000,000,000, 1 height 1,000,000,000)
No two dominoes will be in the same location.
NOTE: 60% of test data has N 5000.

Output
One line, with the number of pushes required.

Sample Input
6
1
2
3
5
6
8

1
2
1
1
1
3

Sample Output
2
Push the domino at location 1 rightward, the domino at location 8 leftward.

Diagram
|
|
|
| | |
| |
|
1 2 3 4 5 6 7 8
Pushing 1 causes 2 and 3 to fall, while pushing 8 causes 6 to fall and gently makes 5 tip
over as well.

Das könnte Ihnen auch gefallen