CF->CodeForces 137C
2013-10-12 18:58
447 查看
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces
137C
Description
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has
never had an easy time with history.
Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year biinclusive
(ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated
task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj.
Your task is simpler: find the number of events that are included in some other event.
Input
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per
line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th
event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are
given in arbitrary order.
Output
Print the only integer — the answer to the problem.
Sample Input
Input
Output
Input
Output
Input
Output
[/code]
Hint
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0.
Submit Status Practice CodeForces
137C
Description
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has
never had an easy time with history.
Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year biinclusive
(ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated
task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj.
Your task is simpler: find the number of events that are included in some other event.
Input
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per
line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th
event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are
given in arbitrary order.
Output
Print the only integer — the answer to the problem.
Sample Input
Input
5 1 10 2 9 3 8 4 7 5 6
Output
4
Input
5 1 100 2 50 51 99 52 98 10 60
Output
4
Input
1 1 1000000000
Output
0
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; struct Events { int b; int e; }events[100001]; bool cmp(Events a, Events b) { return a.b < b.b; } int main() { int t; cin >> t; for (int i = 0; i < t; i++) { scanf("%d %d", &events[i].b, &events[i].e); } sort(events, events + t, cmp); int maxn = events[0].e, num = 0; for (int i = 1; i < t; i++) { if (events[i].e < maxn) { num++; } else { maxn = events[i].e; } } cout << num << endl; return 0; }
[/code]
Hint
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.
In the second example all events except the first one are contained in the first.
In the third example only one event, so the answer is 0.
相关文章推荐
- CF->CodeForces 137B
- CF->CodeForces 256A
- CF->CodeForces 137A
- coldfusion <cfmail>
- <cf>Dubstep
- <cf>System of Equations(水题)
- <cf>Two Problems
- Codeforces 61E Enemy is weak 求i<j<k && a[i]>a[j]>a[k] 的对数 树状数组
- <cf>Sysadmin Bob
- CF 346 B vector<pair> s[100]
- <cf>Schedule
- ACM->CF
- ACM->CF 358A
- <cf>Walking in the Rain
- <cf> A. Cloning Toys
- Codeforces 61E Enemy is weak 乞讨i<j<k && a[i]>a[j]>a[k] 对数的 树阵
- <cf> Funky Numbers
- 关于 codeforces中的 int abs(int x) 还有头文件 # include <algorithm> 不带.h
- <cf>Hexadecimal's theorem
- <cf>Square