# Greedy algorithm

A research laboratory has an expensive scanning probe microscope, shared between different work groups. Every day, groups interested in using the microscope on the next day sive communicate their requests, indicating the time intervals for which they want to book the resource. The head of the laboratory must select a set of compatible requests from each other, and wants to do it in order to satisfy the maximum number of requests. Two requests are among them compatible if the respective time intervals do not overlap. More formally, let us suppose that there are n requests, identified by the numbers 1, · · ·, n. Every request and a couple (si , fi ), where si indicates the instant of beginning and fi the instant of the end of the request the. Obviously, suppose si <fi . We will say that the requests i and j are compatible if fi ≤ sj o fj ≤ si . A subset of requests is compatible if its elements are two-by-two compatible. We ask you to write a program that, given a set of requests, calculates a subset compatible with maximum cardinality. Each request includes four data:

(1) a letter, which is identifies the research group;

(2) the initial instant of the request;

(3) the final instant of the request;

(4) a real number, which represents the cost of the operation to be performed.

The initial moments and final are integers (we will assume that the time frame in which we can use the microscope be divided into 1440 minutes). The program acquires data from standard input. The first line contains the number n of requests. Each subsequent line contains the four data related to a single request, in the order in which they are described above, and separated by spaces. Suppose the data is correct; in particular, that for each request they are worth (1) si < fi and (2) fi <1440. After calculating the solution, the program must print the selected request data, sorted according to the starting point, and the total cost of the solution.

The exercise consists of a form of interval scheduling (or allocation of intervals). In the simple variant proposed here, the solution can be calculated by applying a greedy type algorithm, which at each step chooses, among the residual requests, the one with the minor end instant (excluding, of course, those not compatible with the requests already selected ).

Example of input data format:

6

B 120 280 12.34

B 1100 1187 6.34

C 260 480 9.761

A 180 512 11.34

C 360 900 14.2

D 280 512 9.2

For these data, the suggested algorithm provides the solution (B 120 280 12.34) (D 280 512 9.2) (B 1100 1187 6.34) with a total value of 27.88. There is another acceptable solution of cardinality 3, formed by (B 120 280 12.34) (C 360 900 14.2) (B 1100 1187 6.34), with a value of 32.88. It is emphasized that the exercise does not require the determination of a maximum value solution.

Tietoa työnantajasta:
( 0 arvostelua ) Milan, Italy

Projektin tunnus: #20340906

## Myönnetty käyttäjälle:

george19921014

Hello. I read your proposal and the most import important thing of greedy algorithm is greedy strategy. According to the greedy strategy you can speed up the search and accuracy. Keep in touch. Regards

€25 EUR 1 päivässä
(0 Arvostelua)
0.0

## 8 freelanceria on tarjonnut keskimäärin %project_bid_stats_avg_sub_26% %project_currencyDetails_sign_sub_27% tähän työhön

huangxiangyan

Hi ! How are you ? I have a detail look to your project, and I'm sure I can complete your project. I have 6 years software and mobile developement experiences. Please let's discuss details Lisää

€50 EUR 1 päivässä
(32 arvostelua)
6.1
usamamw141

Hey there, I am expert in Algorithms and C++. Feel free to inbox me any time. Thank you........................

€60 EUR 2 päivässä
(59 arvostelua)
5.2
suju8811

Dear,Client. I am checking your requirements carefully. In fact, I have a good experience and skills in algorithm. Dynamic programmin, greedy, graphics algorithms are my major ones. In fact, I have passed many algorit Lisää

€50 EUR 1 päivässä
(8 arvostelua)
5.1
Tanmoy236

I have a team of 8 people who are extremely good with CSS. HTML, JAVA, PHP and Python. if you provide me the opportunity, i'll finish the work at my earliest without compromising on Quality and will ensure your complet Lisää

€49 EUR 7 päivässä
(7 arvostelua)
4.6
WinterGreenTech

hi wintergreen develops more projects in optimization in matlab. it's need basically 1. encoding variable - scheduling 2. fitness function. - cost 3. constraints based on we have minimize the cost and get the optimi Lisää

€288 EUR 15 päivässä
(3 arvostelua)
3.3
stepan2019

Hi, Dear Sir! I have just read your job description carefully. I think I am a real certain developer whom you are looking for. Can you give me a chance to help you with your job? I sincerely help you with completing Lisää

€30 EUR 7 päivässä
(0 arvostelua)
0.0
somniummisellus

Hello It's rather easy task and I can do it fast because I have a lot of experience in algorithms. Feel free to choose me

€15 EUR 1 päivässä
(1 arvostelu)
0.0