Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <utility>
- #include <algorithm>
- const int OPEN = 0;
- const int CLOSE = 1;
- const int PASSENGERS = 180;
- const int INTERVAL_LENGTH = 60;
- const double INTENSITY = ((double)PASSENGERS) / INTERVAL_LENGTH;
- struct Event {
- int type, minutes;
- Event(int type, int minutes) : type(type), minutes(minutes) {}
- bool operator < (const Event& b) {
- return (minutes < b.minutes || minutes == b.minutes && type == CLOSE && b.type == OPEN);
- }
- };
- int timeToMinutes(int h, int m) {
- return h * 60 + m;
- }
- void minutesToTime(int minutes, int& h, int& m) {
- h = minutes / 60;
- m = minutes % 60;
- }
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- int hours, minutes;
- std::vector<Event> events;
- while (scanf("%d:%d", &hours, &minutes) == 2) {
- int intervalEnd = timeToMinutes(hours, minutes) - 30,
- intervalBegin = intervalEnd - INTERVAL_LENGTH;
- events.push_back(Event(OPEN, intervalBegin));
- events.push_back(Event(CLOSE, intervalEnd));
- }
- std::sort(events.begin(), events.end());
- double currentIntensity = 0;
- std::vector<std::pair<int, double>> changes; // пара: минуты, интенсивность
- for (auto& it : events) {
- if (it.type == OPEN) {
- currentIntensity += INTENSITY;
- } else {
- currentIntensity -= INTENSITY;
- }
- if (changes.empty() || it.minutes > changes.back().first) {
- changes.push_back(std::make_pair(it.minutes, currentIntensity));
- } else {
- changes.back().second = currentIntensity;
- }
- }
- for (auto& it : changes) {
- int hours, minutes;
- double currentIntensity = it.second;
- minutesToTime(it.first, hours, minutes);
- printf("%02d:%02d %.2lf\n", hours, minutes, currentIntensity);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement