Effective Infection Time
Time limit2sMemory limit128 MB
Given each zone infection month and strike month, compute its Effective Infection Time under the half-weight first-year rule, rounded to four decimals.
- Level
Easy3 of 10
- Topics
- Simulation, Math, Implementation
- Solved
- No attempts yet
Problem
You are estimating the threat level of quarantined zones that have been abandoned to the infection. One of the main variables behind a zone's threat level is its EIT (Effective Infection Time). Planning a strike date to reclaim a quarantined zone requires this number. The EIT follows these rules.
- The EIT is a function of two dates: the infection date and the strike date.
- All years are given in A.Z. (After Zombie).
- A month counts toward the EIT only after its last day has passed, so the month of the strike date never counts.
- The first calendar year of the infection counts as EIT.
- If the end of that year is not reached, each month counts for a share of the EIT. A zone infected in January of the first year spreads EIT over 12 months, so one month is EIT. A zone infected in March of the first year spreads EIT over 10 months, so one month is EIT.
- If the end of that year is reached, the year counts as the full EIT no matter which month the infection started. A zone infected in February of 15 A.Z. counts as exactly EIT once December 15 A.Z. has passed, and a zone infected in December of that same year counts as EIT too.
- Every following year counts as EIT. Starting from January, each calendar month is worth EIT.
- Zones infected in the same month share the same EIT for any given strike date, so only the month and the year are given.
The number of months in a year and their order are the same as in the Gregorian calendar we use today.
Input
The first line contains the number of zones (). Two lines follow for each zone.
- The first line is the infection date and the second line is the strike date.
- The first integer of a date is the month () and the second integer is the year (). The year always has 4 digits.
- The strike date never precedes the infection date.
Output
Print the EIT of each zone on its own line, rounded to the fourth digit after the decimal point. Always print the ones digit, even when it is .