15593번 : Lifeguards (Bronze)
문제)
Farmer John has opened a swimming pool for his cows, figuring it will help them relax and produce more milk.
To ensure safety, he hires cows as lifeguards, each of which has a shift that covers some contiguous interval of time during the day.
For simplicity, the pool is open from time until time on a daily basis, so each shift can be described by two integers, giving the time at which a cow starts and ends her shift. For example, a lifeguard starting at time and ending at time covers three units of time (note that the endpoints are "points" in time).
Unfortunately, Farmer John hired 1 more lifeguard than he has the funds to support. Given that he must fire exactly one lifeguard, what is the maximum amount of time that can still be covered by the shifts of the remaining lifeguards? An interval of time is covered if at least one lifeguard is present.
입력 :
The first line of input contains (1≤N≤100). Each of the next lines describes a lifeguard in terms of two integers in the range 0…1000, giving the starting and ending point of a lifeguard's shift. All such endpoints are distinct. Shifts of different lifeguards might overlap.
출력 :
Please write a single number, giving the maximum amount of time that can still be covered if Farmer John fires 1 lifeguard.
풀이)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
// 15593. Lifeguards (Bronze)
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n;
cin >> n;
vector<pair<int, int>> vec;
int a, b;
for (int i = 0; i < n; i++)
{
cin >> a >> b;
vec.push_back(make_pair(a, b));
}
int answer = 0;
for (int i = 0; i < n; i++)
{
int cnt = 0;
vector<bool> visited(1001, false);
for (int j = 0; j < n; j++)
{
if (j == i) continue;
for (int k = vec[j].first; k < vec[j].second; k++)
{
if (visited[k] == false)
{
visited[k] = true;
cnt++;
}
}
}
answer = max(answer, cnt);
}
cout << answer;
return 0;
}
|
cs |
출처 : https://www.acmicpc.net/problem/15593
15593번: Lifeguards (Bronze)
The first line of input contains $N$ ($1 \leq N \leq 100$). Each of the next $N$ lines describes a lifeguard in terms of two integers in the range $0 \ldots 1000$, giving the starting and ending point of a lifeguard's shift. All such endpoints are distinct
www.acmicpc.net
'Develop > 백준 (Cpp)' 카테고리의 다른 글
[백준] 2503번 : 숫자 야구 (C++) (0) | 2024.01.05 |
---|---|
[백준] 1816번 : 암호키 (C++) (0) | 2024.01.05 |
[백준] 1145번 : 적어도 대부분의 배수 (C++) (0) | 2024.01.04 |
[백준] 14697번 : 방 배정하기 (C++) (0) | 2024.01.04 |
[백준] 2851번 : 슈퍼 마리오 (C++) (0) | 2024.01.04 |