Java calculates the maximum number of non-intersection intervals (for example, the number of customers who have made the most appointments within one day)

Source: Internet
Author: User

Java calculates the maximum number of non-intersection intervals (for example, the number of customers who have made the most appointments within one day)

Import java. util. collections;


Public class Tesww {
Public static void main (String [] args ){
Internal reader = new external (System. in );
Int n = reader. nextInt ();
Int [] [] a = new int [n] [2];
For (int I = 0; I For (int j = 0; j <2; j ++ ){
A [I] [j] = reader. nextInt ();
}
}
Sort (a, n); // Sort by the right boundary of the range Hu

Int count = 1;
Int [] [] result = new int [n] [2];
Int max = a [0] [1];
Result [0] [1] = a [0] [1];
Result [0] [0] = a [0] [0];
For (int I = 1; I If (a [I] [0] Continue;
}
Else {
Max = a [I] [1];
Result [count] [0] = a [I] [0];
Result [count] [1] = a [I] [1];
Count ++;
}
}

System. out. println ("up to" + count + "non-repeating intervals :");
For (int I = 0; I System. out. println ("[" + result [I] [0] + "" + result [I] [1] + "]");
}
}
Public static void Sort (int [] [] a, int n ){
For (int I = 0; I For (int j = I; j If (a [j] [1] int temp [] = new int [2];
Temp = a [j];
A [j] = a [I];
A [I] = temp;

}
}
}

}

 

}

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.