Make the most (Hackerrank Codeagon)

Source: Internet
Author: User

Topic links

Problem Statement

codenation is sending N of it employees to a high profiles business Conference and the goal are T O Cover maximum number of presentations, to-create maximum business opportunities. It has a list of all the presentations with their start and end times. You need to help codenation decide an optimal allocation.

The start and end times of a presentation is provided to as a single string and is separated by a space.

Each time was given in the form  hh:mm  and represents a time between  08:00  in the morning and   in the evening inclusive.

Input Format
First line contains an integer n   (number of employees).  
The second line contains Integer  p   (number of presentations).  
< Span id= "mathjax-span-255" class= "math" > p  lines Follow each has conference start time and end time separated by a space.

Constraints
1≤N≤
1≤P≤
Each ofPLines would contain one characters in the formHH:MM HH:MM.
eachhh:mmWould represent a time between 8 am and 8 pm inclusive.
eachMMwould be betweenxx and, inclusive.
in each element of presentations the second time would be strictly later than the first.

Output Format
Print the maximum number of presentations that can is attended.

Note: We can assume the time taken for going from one presentation to another are negligible; i.e. if end time of one presentation is same time as start time of another, a single person can cover both presentations F Rom start to end.

Sample input#00

3508:00 08:0008:00 08:0008:00 08:0008:00 08:0008:00 08:00

Sample output#00

3

explanation#00

All these presentations last all day long. Nobody can cover more than one.

Sample input#01

2509:00 08:0008:00 12:0012:00 08:0008:00 08:0008:00 08:00

Sample output#01

3

Explanation#01
One person can cover the 8-12 presentation and the 12-8 presentation. The other person can cover one of the all-day presentation.

Sample input#02

1508:00 01:0008:25 12:5012:00 12:3012:30 08:0008:00 08:00

Sample output#02

2
Topic Analysis:
is actually an extension of the scheduling problem. That is, given n meetings, each meeting has a start time and an end time, and there are m individuals who ask the M person how many meetings can be attended by up to a total.
If m=1, of course, according to the end time sort, can.
Here, simply deform, set b[j] for the point where the J-person is currently located (initially 0), for the first meeting, if there are more than one person to meet the criteria, select B[j] the largest one.
Attached code:
1#include <cmath>2#include <cstdio>3#include <vector>4#include <iostream>5#include <algorithm>6 using namespacestd;7 8typedef pair<int,int>PII;9 #defineF FirstTen #defineS Second One  A intMain () { -     intN, P; -scanf"%d%d", &n, &P); thePII t[ -]; -      for(inti =0; i < P; i++) { -         intH1, M1, H2, M2, start, end; -scanf"%d:%d%d:%d", &h1, &m1, &AMP;H2, &m2); +Start = (H1 >=8? (H1-8) * -: (H1 +4) * -) +M1; -End = ((H2 >8|| H2 = =8&& m2)? (H2-8) * -: (H2 +4) * -) +m2; +T[i] =PII (end, start); A     } atSort (T, T +P); -      for(inti =0; i < P; i++) Cerr << t[i]. S <<' '<< T[i]. F <<Endl; -     intAns =0; -     intnow[ -] = {0}; -      for(inti =0; i < P; i++) { -         intx =-1, last =-1; in          for(intj =0; J < N; J + +) { -             if(T[i]. S >=Now[j]) { to                 if(Now[j] >Last ) { +x =J; -Last =Now[j]; the                 } *             } $         }Panax Notoginseng         if(X! =-1) { -ans++; theNOW[X] =T[i]. F; +         } A     } theprintf"%d\n", ans); +      -     return 0; $}

Make the most (Hackerrank Codeagon)

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.