Expected Flight Delay

시간 제한1초메모리 제한1024 MB

요약
회의 전날부터 거꾸로 성공 확률을 누적해, 요구한 확률 이상이 되는 가장 늦은 출발일을 구한다.
난이도

쉬움10점 중 3점

유형
수학, 확률, 시뮬레이션, 구현
정답자
아직 제출이 없습니다

문제

Once upon a time, there was a businesswoman named Grace who lived in New York City, New York and frequently traveled to Des Moines, Iowa on a regular daily flight for work. Unfortunately, there was one big problem: Flights from New York to Des Moines were notoriously unreliable, especially on weekends. The weather, maintenance issues, and other unpredictable factors always seemed to interfere.

Grace knew from her previous experiences that it would be very handy to have an app that would let her enter the day of the week of an upcoming meeting, the importance of arriving on time (she arrives on time if she successfully departs the day before, at the latest), and the probabilities of successfully flying out on weekdays (Monday-Friday) and on weekends (Saturday-Sunday). This would help her decide what day to schedule her flight in order to have confidence that she could reach Des Moines on time. Since her skills in programming and knowledge of probability are somewhat lacking, she is asking you to come up with the app.

As an example, suppose the meeting date is a Monday. Let the chance of success on weekdays be p_wday=80p\_{\mathrm{wday}}=80\\%, and on weekends be p_wend=60p\_{\mathrm{wend}}=60\\%. Let the importance of getting to the meeting on time be 9090\\% certainty. If Grace tries to fly on Sunday, the chance of her making it on time would simply be 6060\\%. Not great, and not the 9090\\% assurance she wants, either. Perhaps flying on Saturday instead will work. This way, if Saturday's flight is canceled, she could still try again on Sunday.

The probability of her leaving by Sunday in this case would be 6060\\%\ \textrm{(chance of Saturday's flight being good)} + 40\\%\ \textrm{(chance of Saturday's flight being bad)} \cdot 60\\%\ \textrm{(chance of Sunday's flight being good)} = 84\\%. That's still not good enough.

If we add Friday as an option and calculate the probability Grace leaves by Sunday given the weekday 8080\\% chance of success, we will get 0.8+0.2⋅0.6+0.2⋅0.4⋅0.6=96.80.8 + 0.2 \cdot 0.6 + 0.2 \cdot 0.4 \cdot 0.6 = 96.8\\%. That is quite sufficient for Grace!

입력

The only line of input contains four space-separated integers. The first is in the range \[1,7]\[1,7] inclusive and indicates the meeting day of the week, with 11 designating Sunday, 22 Monday, and so forth. The next two integers are the percentage chances of successful flights on weekdays and weekends p_wdayp\_{\mathrm{wday}} and p_wendp\_{\mathrm{wend}} (0≤p_wday,p_wend≤100)(0 \leq p\_{\mathrm{wday}}, p\_{\mathrm{wend}} \leq 100). At least one of p_wdayp\_{\mathrm{wday}} and p_wendp\_{\mathrm{wend}} is nonzero. The fourth is the importance factor of making the meeting on time p_impp\_{\mathrm{imp}}, expressed as a percentage (1≤p_imp≤99)(1 \leq p\_{\mathrm{imp}} \leq 99).

Let p(i)p(i) be the percent chance that Grace makes it to her meeting on time if she starts trying to fly there ii days before the meeting. It is guaranteed that min⁡_i≥1∣p(i)−p_imp∣>10−6\min\_{i \geq 1} |p(i) - p\_{\mathrm{imp}}| > 10^{-6}.

출력

Print a string of the form Try to leave on DEPDAY, N days before the MEETDAY meeting. In this string, DEPDAY is the day of the week (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday) closest to the meeting date on which to schedule the flight to guarantee that the percent chance of Grace making the meeting is at least p_impp\_{\mathrm{imp}}. N is the number of days to leave before the day of the meeting: note that Grace may need to leave more than 77 days early to meet her importance factor requirement. Finally, MEETDAY is the day of the week of the meeting. Print day instead of days if N is 11. See the sample output for examples of how to format this string.

예제2

  1. 예제 1

    입력
    2 80 60 90
    
    예상 출력
    Try to leave on Friday, 3 days before the Monday meeting.
    
  2. 예제 2

    입력
    1 40 60 10
    
    예상 출력
    Try to leave on Saturday, 1 day before the Sunday meeting.