Hud_2037-not AC this summer

Source: Internet
Author: User

[Cpp]/* topic general idea: Give the start time and end time of a program, and find the maximum number of complete programs to watch * solution: sort by program time first, because it must be a complete program, therefore, you must select the first program to start and end as soon as possible after the last program ends. */# Include <cstdio> # include <cstring> # include <algorithm> using namespace std; # define MAX 101 struct node {int x, y;} a [MAX], B [MAX]; bool cmp (node a, node B) {if (. x! = B. x) {return. x <B. x;} else {return. y <B. y ;}} int main (int argc, char const * argv []) {# ifndef ONLINE_JUDGE freopen ("test. in "," r ", stdin); # endif int cnt, ans; while (scanf (" % d ", & cnt), cnt) {ans = 0; for (int I = 0; I <cnt; I ++) scanf ("% d", & a [I]. x, & a [I]. y); sort (a, a + cnt, cmp); for (int I = 0; I <cnt; I ++) {if (! I) B [++ ans] = a [I]; else {if (a [I]. x> = B [ans]. y) {// the start time is later than the end time of the program. Add B [++ ans] = a [I];} else if (a [I]. y <B [ans]. y) {// if the end time is earlier than the end time of the program, replace B [ans] = a [I] ;}} printf ("% d \ n ", ans);} return 0 ;}

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.