P1803 messy yyy, P1803 messy yyy

Source: Internet
Author: User

P1803 messy yyy, P1803 messy yyy
Background

It's almost noip, and yyy is very nervous!

Description

There are now n competitions in each major oj, And the start and end time of each competition is known.

Yyy believes that the more participating games, the better the noip will be (false)

So he wants to know how many competitions he can attend.

Because yyy is a shopping spree, you must start and end a game and cannot join two or more games at the same time.

Input/Output Format Input Format:

The first line is an integer n, And the next n lines are two positive integers (ai). bi (ai <bi) indicates the start time and end time of the game.

Output Format:

The maximum number of competitions allowed by an integer.

Input and Output sample Input example #1:
30 22 41 3
Output sample #1:
2
Description

For 20% of the data, n ≤ 10;

For 50% of data, n ≤ 1000;

For 70% of data, n ≤ 100000;

For 100% of data, n ≤ 1000000, 0 ≤ ai <bi ≤.

 

P [I] indicates that the time at which the I-th match exists starts from p [I]. If there are two sets of matches with the same time, then we obviously want to get the group with a larger p [I], and replace p [I] with a larger starting time.

 

After such preprocessing, f [I] indicates that at least a few matches can be played at the position at the time point I. If there is a p [I] For I, for f [I], take the maximum value among f [I-1] (not in the competition) and f [p [I] (in the Competition)

The final answer to the question is f [1 ~ Maximum Value of maxint of endingtime]

 

1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cmath> 5 using namespace std; 6 void read (int & n) 7 {8 char c = '+'; int x = 0; bool flag = 0; 9 while (c <'0' | c> '9 ') 10 {11 c = getchar (); 12 if (c = '-') flag = 1; 13} 14 while (c> = '0' & c <= '9') 15 x = x * 10 + c-48, c = getchar (); 16 flag = 1? N =-x: n = x; 17 18} 19 const int MAXN = 1000001; 20 int n; 21 int dp [1000001]; // dp [I] [0] indicates the number of marks 22 on the day I/dp [I] [1] indicates the amount of USD 23 on the day I, int p [MAXN]; 24 struct node25 {26 int bg, ed; 27} a [MAXN]; 28 int main () 29 {30 read (n); 31 memset (p,-1, sizeof (p); 32 int maxt = 0; 33 for (int I = 1; I <= n; I ++) 34 {35 read (a [I]. bg), read (a [I]. ed); 36 p [a [I]. ed] = max (p [a [I]. ed], a [I]. bg); 37 maxt = max (maxt, a [I]. ed); 38} 39 int ans = 0; 40 for (int I = 0; I <= maxt; I ++) 41 {42 if (p [I]! =-1) 43 dp [I] = max (dp [I-1], dp [p [I] + 1); 44 else45 dp [I] = dp [I-1]; 46 ans = max (ans, dp [I]); 47} 48 printf ("% d", ans); 49 return 0; 50}

 

 

 

Related Keywords:
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.