Time Limit: 2 seconds
It’s dinner time for your pet fox! His meal consists of
After taking an initial sip of water, your fox begins his meal. Every time he eats a cracker, its tastiness is equal to the absolute difference between its temperature, and the temperature of the last thing he ate or drank (be it the previous cracker he ate, or a sip of water, whichever he consumed most recently). He can drink some water whenever he wants, and can eat the crackers in any order.
Depending on the order in which your fox eats and drinks, the total tastiness of the crackers consumed may vary. What are the minimum and maximum values it can have?
The first line contains two integers,
For at least 30% of the marks for this problem,
The output is one line containing two integers: the minimum and maximum total tastiness your fox can experience during his meal, respectively.
3 20
18
25
18
7 16
To minimize the total tastiness, the fox might drink water, eat the
first cracker, eat the third cracker, drink more water, and finally eat
the second cracker. He will then experience temperatures of 20, 18, 18,
20, and 25 degrees Celsius, and the crackers will have tastiness values
of
To maximize the total tastiness, the fox might drink water, and then
eat the crackers in order. He will then experience temperatures of 20,
18, 25, and 18 degrees Celsius, and the crackers will have tastiness
values of
Time Limit: 2 seconds
There are many well-known algorithms for finding the shortest route from one location to another. People have GPS devices in their cars and in their phones to show them the fastest way to get where they want to go. While on vacation, however, Troy likes to travel slowly. He would like to take the longest route to his destination so that he can visit many new and interesting places along the way.
As such, a valid route consists of a sequence of distinct cities
He does not want to visit any city more than once. Can you help him find the longest route?
The first line of input contains two integers
The next
For at least 30% of the marks for this problem,
Output a single integer, the length of the longest route that starts
in city 0, ends in city
3 3
0 2 5
0 1 4
1 2 3
7
The shortest route would be to take the road directly from 0 to 2, of
length 5 km. The route going from 0 to 1 to 2 is
Time Limit: 15 seconds
A new era of aviation is upon us - the first solar-powered jumbo jets are about to be made available for public travel! However, this cutting-edge technology raises some safety concerns, as the rays of sunlight which power these planes can be blocked by other objects in the sky. As such, some statistics must first be calculated concerning the planned initial flights.
We consider a set of
Planes also have an inteference factor: each plane
The solar panels on each plane are rather strange, in that they can only collect energy from directly above the plane. This means the sunlight that a given plane can absorb can be obstructed by other planes which occupy the same x-coordinate as it, and have a larger y-coordinate than it. In particular, their effectiveness is reduced based on the sum of the interference factor of all such planes.
Given this information, as well as a fixed distance constant
The first line contains four space-separated integers:
Each of the next
Each of the next
For 40% of the marks for this problem,
The output consists of
12 4 3 3
1 4 5
2 2 3
6 3 6
2 1
1 8
3 0
11
6
0
Below is a diagram of the planes’ flight paths:
The first query is for plane 2 over x-coordinates in the inclusive
range
For the second query, plane 1 could be covered by plane 3 while it
has x-coordinate less than 10, and will not be covered by anything while
it has x-coordinate greater than or equal to 10. Thus, it is only
possibly interfered with by plane 3 with interference factor
Neither plane 1 nor plane 2 can possibly be directly above plane 3 until it reaches x-coordinate 10, so the answer to the final query is 0.
Time Limit: 5 seconds
Guarding a bank during Christmas night can get very boring. That’s why Barry decided to go skating around the parking lot for a bit. However the parking lot isn’t empty as the other security guards have their cars parked there. So Barry decides to push their cars out of the parking lot. He notices that their cars are parked facing either North, South, East or West. Since the parking lot is frozen, pushing a car will make it slide until it has left the parking lot or hit another car. Cars can only be pushed in the direction which they are facing. Not wanting to crash the cars, Barry enlists your help to find out what order he has to push the cars so as to clear the parking lot.
The first line contains two integers
For at least 70% of the marks for this problem,
Output the order in which the cars have to be pushed so as to clear
the parking lot without crashes. Output each car in the form
You can assume there will always be at least one valid solution.
If there are multiple possible solutions, output any valid solution.
5 5
.....
.E.S.
.....
.....
.N.E.
(4,3)
(1,3)
(1,1)
(4,1)
The only car that isn’t initially blocked by another car is the one
at
4 3
...
.N.
.S.
...
(1,1)
(2,1)
Either car could be pushed first to clear the parking lot, so this output is acceptable (as would the output with the lines outputted in reverse order).
Time Limit: 1 second
Problem Description
Computer scientists don’t often help percussionists, but today, that will change. Since we cannot help all percussionists at the same time, we focus on timpanists first. By way of terminology, the timpani is the plural of timpano and the player of the timpani is a timpanist.
A timpano is a large drum which can be tuned to a certain pitch, and
a timpanist uses an ordered set of
{ F, F#, G, G#, A, A#, B, C, C#, D, D#, E }
At a given time, a timpano can only be used to play the pitch it is
currently tuned to, and thus the timpanist can play a note
Every note in this piece is in the range of a single octave, from F
up to E, which means that the above list of possible notes is in
ascending order of pitch. In order to make your computation slightly
easier, we will use integers from
Integer | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Tone | F | F# | G | G# | A | A# | B | C | C# | D | D# | E |
(i.e., F will be represented by 1, F# by 2,
These are the only pitches to which timpani can be tuned.
Before the piece starts, the timpanist can freely tune each timpano
to any pitch they’d like. However, during the piece, they may need to
quickly retune them in between notes in order to be able to play the
required pitches at the correct times. The drums are numbered from
Input Specification
The first line contains two integers,
For 60% of the marks for this problem,
Output Specification
The output is one line containing one real number (rounded off to 2
decimal places), which is the maximum amount of time (in seconds) that
the timpanist can have for their fastest retuning, or
0.00
if no retunings are necessary
7 1
100 1
120 3
130 5
140 6
150 8
165 10
170 12
5.00
With just 1 drum, the timpanist must retune it after every note in order to play the following one.
With 2 drums, the answer would instead be 10.00 (achieved by leaving the higher drum tuned to pitch 12).
12 4
0 1
2 1
3 3
6 1
9 6
12 5
21 1
23 1
24 3
27 1
30 8
33 6
4.50
The first 6 notes include only the 4 pitches 1, 3, 5, and 6. Similarly, the last 6 include only 1, 3, 6, 8.
The single optimal strategy involves pre-tuning the 4 drums to 1, 3, 5, and 6. After the sixth note, the timpanist can take 4.5 seconds to retune the highest drum to an 8, and then another 4.5 seconds to retune the second-highest drum to a 6, finishing just in time to play the seventh note.
2 4
40287 8
20338194 8
0.00
This is a more typical timpani part, involving just one note, and thus no retuning.
Time Limit: 10 seconds
It’s time for a vacation! You are sick and tired of C shells, so you decide to become a seashell collector.
For your vacation, you have decided to visit the beautiful island
nation of Cartesia. It is well-known for having a lovely square beach
that is composed of an
There are
Complicating matters is a glorious dodo bird running around the
beach. At a given moment, it may decide to bury an egg in a grid cell
(including grid cells that have eggs or shells already). The bad news is
that if the
After all is said and done, you decide to sit back, go back to programming, and simulate the digging instead. You will be computing the probability that your scoop, when chosen uniformly from all valid possible scoops, will make at least a given minimum profit (to pay off your student loans) at different points in time. Who wants to get all sweaty from shoveling on a beach anyway?
The first line of input contains two integers
The second line of input contains the integer
The next line contains
1
2
For at least 15% of the marks for this question,
For an additional 25% of the marks for this question, all update operations will occur before all query operations.
For each query operation, output on one line the probability that a random scoop would contain at least the desired number of different types of shells.
Your answer must be within
4 2
3
3 1 1 2 3 4 2
3 1 4 2 3 3 2
4 2 1 2 4 4 1 4 4
6
2 2
2 3
1 2 3
2 2
2 3
2 4
0.88889
0.33333
0.44444
0.11111
0.00000
Initially, we have the following arrangement of shells (with the
first shells in the input being labelled as
1 | 2 | ||
3 | 1, 2 | 3 | |
2 | |||
3 | 1 | 3 |
and our shovel will scoop up a
With no eggs present, 8 of the 9 scoops contain at least two species of shells and 3 of the 9 scoops contain three species of shells.
An egg is then dropped into the cell that contains
Then, 4 of the 9 scoops contain at least two species of shells and no eggs and only 1 scoop (the bottom-leftmost scoop) would contain all three species of shells and no eggs. The final output indicates there are no scoops which contain 4 different species of shells.