Weather Forecasting
Time limit1sMemory limit128 MB
Parse four weather forecast lines, score each sentence by phenomenon and qualifier, weight forecasts by day, and test whether the total is under 0.25.
- Level
Medium4 of 10
- Topics
- String, Implementation, Simulation, Math
- Solved
- No attempts yet
Problem
Because there are so many news sources online, it takes real effort to work out which ones you can trust for weather forecasts. To weed out the least reliable ones, you want a simple model that scores a news agency automatically. The model reads an agency's forecasts of today's weather that were published on each of the previous four days, and decides whether those forecasts correctly warned that travelers would be affected by bad weather. For simplicity we only consider days on which the weather actually caused problems.
A forecast is one or more sentences, published on an earlier day, that refer to today's weather. Each sentence contains exactly one phenomenon and zero or one qualifier. On their own, phenomena are good, ambiguous, or bad:
By default a sentence states a 100% chance of its phenomenon. A qualifier changes that chance. For good and bad phenomena, the qualifiers and the chances they imply are:
For an ambiguous phenomenon, exactly one qualifier is always present, and it is numeric; its value decides whether the otherwise-ambiguous phenomenon is actually good or bad (the numeric qualifier only sets good vs. bad, and the chance stays 100%).
- The qualifier for high(s) and low(s) takes one of two forms: an integer between 0 and 80, or one of the range words 'upper', 'lower', 'mid' followed by an integer rounded to the nearest 10 degrees (for example, "upper 40s"). A high is good if the temperature is at least 60; a low is good if the temperature is at least 50.
- The qualifier for wind(s) has a single form: two integers joined by the words "to" and "mph" (for example, "5 to 10 mph"). If the second integer is at least 25 the phenomenon is bad, otherwise it is good.
The score of a sentence is the chance of its phenomenon, taken as positive when the phenomenon is good and negative when it is bad. The score of a forecast is the average of the scores of its sentences.
Forecasts get more accurate as the target day approaches, so when combining an agency's four forecasts we weight each one by , where is the number of days in advance the forecast was made (a forecast made yesterday for today has weight ). The agency's total score is the sum of these weighted forecast scores.
Input
The first line contains an integer , the number of data sets. It is followed by data sets, each consisting of exactly four lines. Within a data set, the -th line (counting from 1) holds the forecast that was published days before the day in question.
Output
For each data set, first print "Data Set x:" on its own line, where x is the data set's number (starting from 1). On the next line print "YES" if the total score is less than 0.25 (meaning the agency correctly forecast bad weather), and "NO" otherwise. Separate the output of consecutive data sets with a single blank line.