Skip to content

Commit 9d10dfb

Browse files
committed
[kattis] Add C++ solution for Happy Telephones
1 parent 1dc20c5 commit 9d10dfb

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

kattis/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ There are solutions for the following
334334
1. [Synchronizing Lists](synchronizinglists.cc) ([problem site](https://open.kattis.com/problems/synchronizinglists))
335335
1. [T9 Spelling](t9spelling.cc) ([problem site](https://open.kattis.com/problems/t9spelling))
336336
1. [Tarifa](tarifa.cc) ([problem site](https://open.kattis.com/problems/tarifa))
337+
1. [Happy Telephones](telephones.cc) ([problem site](https://open.kattis.com/problems/telephones))
337338
1. [Temperature Confusion](temperatureconfusion.py) ([problem site](https://open.kattis.com/problems/temperatureconfusion))
338339
1. [Test](test2.cc) ([problem site](https://open.kattis.com/problems/test2))
339340
1. [The Last Problem](thelastproblem.py) ([problem site](https://open.kattis.com/problems/thelastproblem))

kattis/telephones-1.ans

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
2
3+
1
4+
0

kattis/telephones-1.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
3 2
2+
3 4 2 5
3+
1 2 0 10
4+
6 5 5 8
5+
0 6
6+
8 2
7+
1 2
8+
8 9 0 10
9+
9 1
10+
10 1
11+
0 0

kattis/telephones.cc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// https://open.kattis.com/problems/telephones
2+
#include <bits/stdc++.h>
3+
4+
using namespace std;
5+
6+
const int N = 1e4;
7+
pair<int, int> calls[N];
8+
9+
int main() {
10+
cin.tie(0), ios::sync_with_stdio(0);
11+
while (1) {
12+
int n, m;
13+
cin >> n >> m;
14+
if (!n) break;
15+
for (int i = 0; i < n; i++) {
16+
int a, b, c, d;
17+
cin >> a >> b >> c >> d;
18+
calls[i] = {c, c + d};
19+
}
20+
while (m--) {
21+
int start, end;
22+
cin >> start >> end;
23+
end += start;
24+
int c = 0;
25+
for (int i = 0; i < n; i++) {
26+
int s, e;
27+
tie(s, e) = calls[i];
28+
c += s < end && e > start;
29+
}
30+
cout << c << '\n';
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)