SGU-133-Border (simple statistics)
133. Border
Time limit per test: 0.25 sec.
Memory limit per test: 4096 KB
Along the border between statesAAndBThere areNDefense outposts. For every outpostK, The interval[Ak, Bk]Which is guarded by it is known. Because of financial reasons, the president of countryADecided that some of the outposts shoshould be abandoned. In fact, all the redundant outposts will be abandoned. An outpostIIs redundant if there exists some outpostJSuch thatAjiAndBi . Your task is to find the number of redundant outposts.
Input
The first line of the input will contain in the integer numberN(1 <= N <= 16 000).NLines will follow, each of them containing2Integers:AkAndBk(0 <= Ak <Bk <= 2 000 000 000), Separated by blanks. All the numbersAkWill be different. All the numbersBkWill be different.
Output
You shoshould print the number of redundant outposts.
Sample Input
50 102 93 81 156 11
Sample Output
3
Author |
: Mugurel Ionut Andreica |
Resource |
: SSU: Online Contester Fall Contest #2 |
Date |
: Fall 2002 |
Train of Thought: sort the integer pairs in ascending order of the first value, and traverse them later. If the second value of each operation is smaller than the maximum value of the second value, ans ++, note that do not add EOF, Will PE
AC code:
#include
#include
#include #include
using namespace std;struct node {int x, y;}a[16005];int N;bool cmp(node a, node b) {return a.x < b.x;}int main() {scanf("%d", &N);for(int i = 0; i < N; i++) {scanf("%d %d", &a[i].x, &a[i].y);}sort(a, a + N, cmp);int ans = 0;int MAX = a[0].y;for(int i = 1; i < N; i++) {if(a[i].y < MAX) ans ++;else MAX = a[i].y;}printf("%d\n", ans);return 0;}