On a whim, you "invested" $200 in cryptocurrency. After monitoring the markets for a few days, you notice that the (fiat) value of your portfolio seems to be changing according to the formula
$$$$$$v(t) = 100e^{-A t} + 100 e^{-B t}$$$$$$ where $$$t$$$ is the time in days since you bought the cryptocurrency and $$$A$$$ and $$$B$$$ are positive constants. From your calculus classes, you know that $$$v(t)$$$ is a strictly decreasing function.
You don't want to lose all of your money, so you've decided to sell when the value of your portfolio becomes half of its starting value: in other words, when $$$v(t) = 100.$$$
Assuming that the value of your portfolio continues to follow the formula above, at what time (value of $$$t$$$) should you sell the cryptocurrency?
The only line of input consists of two space-separated real numbers $$$A$$$ and $$$B$$$. These constants satisfy $$$0.5 \leq A, B \leq 50$$$.
Print the value of $$$t$$$ for which $$$v(t) = 100$$$. Your answer will be judged correct if it matches the judge solution with absolute or relative error $$$10^{-4}$$$.
Hint: this means you need to print your answer with many digits of precision.
0.67 42.0
0.0725691653788089752197265625
3.14159265 2.71828
0.2370033897459506988525390625
All popular languages have built-in support for calculating $$$e^x$$$.
Java:
double result = Math.exp(x);
Python:
import math
result = math.exp(x)
C++:
#include <cmath>
double result = std::exp(x);
You recently got hired by a company in Orlando, and you've decided to take advantage of all of the theme parks there. You and your friends have coordinated and decided on the days in the coming year that you wish to visit the theme park.
Now, you need to buy tickets. The theme park offers several types of ticket: each ticket type has a certain price and grants you admission to the park for a certain number of consecutive days. (You don't have to attend the park on all of those days if you don't want to; but you won't get a refund for unused days!). You can buy multiples of each ticket type and you may assume that all ticket types are available starting on all days of the year (no day is sold out).
What is the cheapest total cost you need to pay for admission to the park on your chosen days?
The first line of input contains two space-separated integers $$$D$$$ and $$$T$$$: the number of days you wish to visit the park $$$(1 \leq D \leq 365)$$$ and the number of ticket types available $$$(1 \leq T \leq 10).$$$ The next line contains $$$D$$$ strictly increasing space-separated integers $$$d_i$$$ $$$(1 \leq d_i \leq 365)$$$: the days of the year that you want to visit the theme park. Each of the final $$$T$$$ lines describe a ticket type. Each line has contains two space-separated integers $$$k$$$ and $$$p$$$: the number of consecutive days that you can enter the park using a ticket of this type $$$(1 \leq k \leq 365)$$$; and the cost of the ticket in dollars $$$(1 \leq p \leq 10\,000)$$$.
Print an integer: the fewest dollars you need to spend for admission to the park on all of your chosen days, assuming you buy tickets optimally.
6 22 4 7 9 364 3651 1007 199
498
6 31 2 3 4 5 63 1006 2505 150
200
One optimal way to buy tickets for Sample Input 1 is to buy two 7-day tickets and one 1-day ticket. The 7-day tickets covers days (2, 4, 7) and (364, 365), and the 1-day ticket covers day 9.
A famous theorem in number theory says: for any two positive integers $$$a, b$$$ with no common factors, there are infinitely many primes $$$p$$$ of the form $$$p = ax + b$$$ (for $$$x$$$ an integer).
For example, here are some primes of the form $$$4x + 1$$$: $$$5, 13, 17, 29, 37, \ldots$$$.
Here are some primes of the form $$$4x + 3$$$: $$$3, 7, 11, 19, 23, 31, \ldots$$$.
There is only one prime of the form $$$4x + 2$$$, but that is not a counterexample since $$$4$$$ and $$$2$$$ have a common factor.
You would like to check the plausibility of the above theorem computationally. Given $$$a$$$ and $$$b$$$, how many of the primes less than ten million are of the form $$$ax + b$$$?
The only line of input contains two space-separated integers $$$a$$$ and $$$b$$$. They satisfy the bounds $$$1 \leq b \lt a \leq 10^4$$$. It is guaranteed that $$$a$$$ and $$$b$$$ are relatively prime (share no common factors).
Print the number of primes less than ten million of the form $$$ax + b$$$ (for $$$x$$$ an integer).
4 1
332180
4 3
332398
10000 9999
168
In Boggle, you are given a grid of letters, and need to form words using letters from the grid.
To form a word, you start at any square, then trace a path through the grid by moving from your current square to any adjacent square (in the four orthogonal or four diagonal directions). Each square you visit adds a letter to the word. You cannot visit the same square more than once.
For example, given the following grid:
ABCD
HGFE
IJOL
PONM
it is possible to form MOON, FLED, and HAG. HIGH is not a valid word you can form using the grid, because it requires visiting the same square (the H) more than once.
Given a grid and a target word, is it possible to form the target word according to the above rules?
The first four lines of input contain exactly four characters each, and specify the letter grid. The fifth line of input contains the target word, which will have length at least $$$3$$$ letters and at most $$$10$$$ letters.
"Letters" in this problem are uppercase ASCII characters A through Z.
Print POSSIBLE if it is possible to form the target word using the Boggle rules described above. Print IMPOSSIBLE otherwise.
ABCDHGFEIJOLPONMFLED
POSSIBLE
ABCDHGFEIJOLPONMHIGH
IMPOSSIBLE
ZZZZZZZZZZZZZZZZZZZZZZZZZZ
POSSIBLE
Duplicate letters in the grid are allowed (like the O in Sample Input 1.)
Winter is coming. To help the state prepare for the annual freak Austin winter storm, you've volunteered to build an app that visualizes historical temperature statistics.
The state has numbered its counties from $$$1$$$ to $$$C$$$, in a way that nearby counties geographically have nearby numbers. The state has also provided you with the record low temperature recorded for each county.
Users will interact with your app in two ways.
1. They can ask your app to report the lowest recorded temperature across all counties in the range $$$[L, R]$$$ inclusive. In other words, if $$$T_i$$$ is the lowest temperature recorded for county $$$i$$$, this query asks for $$$$$$\min\left(T_L, T_{L+1}, \ldots, T_{R-1}, T_R\right).$$$$$$
2. Users can report a temperature for a county. If this temperature is lower than the lowest historical temperature in that county, you should take the new value into account for all subsequent queries.
Implement the backend for an app with this functionality.
The first line of input contains two space-separated integers $$$C$$$ $$$(1 \leq C \leq 50\,000)$$$ and $$$Q$$$ $$$(1 \leq Q \leq 100\,000)$$$: the number of counties in the state, and the number of times the user interacts with the app.
The next line contains $$$C$$$ space-separated integers $$$T_i$$$ $$$(-50 \leq T_i \leq 120)$$$: the record low temperature of each county in the state.
The final $$$Q$$$ lines record the user interactions with your app, in order. Each interaction has one of the following two forms:
It is guaranteed that at least one of the $$$Q$$$ interactions is of type QUERY.
For each interaction of type QUERY, print the requested lowest recorded temperature across those counties (see above). Print one query result per line.
5 65 -10 15 0 -2QUERY 1 5OBSERVED 2 15QUERY 1 3OBSERVED 4 -19OBSERVED 5 -3QUERY 1 5
-10 -10 -19