SGU-133-Border (simple statistics)

Source: Internet
Author: User
Tags cmath

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;}
    
   
  







Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.