Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Programming Languages
Python
Taskcproblem calendar
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="snorllaxxx, post: 5174961, member: 96454"] Here is algorith, help to realize Data Reading: The first step is to read the input data, which is the year and the day of the week of January 1, as well as the dates of all holidays. Calendar Generation: The next step is to create a dictionary, i.e., a calendar for the given year, taking into account whether the year is a leap year or not. Weekdays are marked as 0, Sundays and Saturdays as 1. Holiday Indication: Then, iterate through the list of holidays, and if holiday falls on a weekday, mark it as 2, replacing the corresponding element in the calendar (not 1 because it cannot be moved when creating the longest chain); if it falls on a weekend, place a one here (i.e., Sunday or Saturday), but replace the next working day after the weekend with festive (i.e., 2). Calculations and Weekend Transposition: With this internal calendar representation, you now need to calculate how many weekends can be moved to weekdays in such a way as to maximize the number of consecutive days of rest without violating the condition "no more than 6 working days in a row". When creating a chain, swap 0 and 1. It can be seen that under a normal schedule, weekdays always go 5 in a row, so all Sundays can be boldly changed to weekdays and a chain can be built from them. Also, since 2 cannot be moved, they should be included in a chain of 2 and 1, and it is necessary to ensure that the chain includes a maximum number of twos (but they cannot be moved). Counting the Maximum Continuity Value: Finally, walk through the resulting calendar and count the maximum number of consecutive days off (days marked '1' or '2'). Answer Output: Once the maximum duration of consecutive days off has been found, print that number. [/QUOTE]
Verification
Post reply
Forums
Programming Languages
Python
Taskcproblem calendar
Top