Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- собес 4
- Есть кинотеатр из 1 ряда, в котором n сидений. Некоторые заняты, нужно определить место, которое дальше от всех занятых
- /*
- int find_seat(const std::vector<int>& row)
- find_seat(row={1, 0, 0, 0, 1}) -> 2
- find_seat(row={1, 0, 1, 0, 0, 1, 0, 0, 0, 1}) -> 2
- find_seat(row={1, 0, 1, 0}) -> 1
- */
- max(max_first_zeros, max_last_zeros, (max_len + 1) / 2)
- int find_seat(std::vector<bool>& row) {
- const int n = row.size();
- int answer = 0;
- int cur = 0;
- int prefix_zeros = 0;
- // cur | [i - cur + 1, i] = "0...0"
- // i = 3
- // cur = 1
- // row[3:3+1] == [False]
- for (int i = 0; i < n; ++i) {
- if (row[i] == true) {
- cur = 0;
- } else {
- if (cur == i) {
- prefix_zeros++;
- }
- cur++;
- }
- answer = max(answer, cur);
- }
- answer = std::max({prefix_zeros, (answer + 1) / 2, cur});
- return answer;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement