celebrate Christmas

Christmas is the festival of joy, peace and happiness. It is the special festival to celebrate the birth of Jesus Christ. Christmas has become a symbolic time for a life of peace and love.

On this occasion we should share, give something to the less privileged, spend time with loved ones and enjoy the best moments together. On this occasion, many people around the world travel to other places to celebrate Christmas. In India, Goa is the most popular place for international travelers to celebrate such a unique festival. But travelers can apply for a travel visa for India through Indiaevisas.org. Goa has a great impression of celebrating Christmas with immense pomp and show. Thousands of foreign and local tourists visit here. The whole city is decorated with lights and parties are organized on the beaches all night.

c ++ – MIT Puzzle: The best time to celebrate

This problem is from the MIT course and I have implemented it in C ++. Please check and suggest improvements.

There is a party for celebrating celebrities to attend
because you won a ticket at your office lottery. Because of the high
Demand for tickets is only an hour but you come to
Choose which, as you have received a special ticket. You have access to
A schedule that specifies exactly when each celebrity will attend
the party. You want to take as many pictures with celebrities as possible
possible to improve your social reputation. That means you want to go
for the hour in which you at hob-nob with the maximum number of
Celebrities and get selfies with each of them.

We get a list of intervals that match every celebrity
comes and goes. Suppose these intervals are (i, j), where i and j
Correspond to hours. That is, the interval is closed on the left side
Side and open on the right. This just means that the
Celebrities will celebrate at and through the i-th hour, but will have it
left, if the j. Hour begins. So even if you arrive punctually on the th
Hour, you will miss this particular celebrity.

Here is an example:


When is the best time to attend the party? That is, what hour should be
you go after?


struct range
    int start = 0;
    int end = 0;

    range() = default;
    range(int start_time, int end_time):

int celeb_density(std::vector& schedule)
    //sort according to start_time
    auto by_start_time = ()(const range &a, const range &b)
        return a.start < b.start;
    std::sort(schedule.begin(), schedule.end(), by_start_time);

    int party_start = schedule(0).start;   //Party start time
    int party_end = schedule(schedule.size()-1).end;  //Party end time
    int max_count = 0, curr_max = 0, best_time, curr_best_time;

    int i = party_start;
    while (i < party_end)
        for (int j = 0; j < schedule.size(); ++j)
            if (i == schedule(j).start)
                curr_best_time = i;
            else if (i < schedule(j).start)

            if (i == schedule(j).end)
        if (curr_max > max_count)
            max_count = curr_max;
            best_time = curr_best_time;
    return best_time;

int main()
    std::vector schedule;

    int number_of_celebs;
    std::cout << "Enter number of celebrities attending party: ";
    std::cin >> number_of_celebs;

    std::cout << "Enter entry time and exit time for a celebrityn";
    for (int i = 0; i < number_of_celebs; ++i)
        int s, e;
        std::cin >> s >> e;
        schedule.push_back(range(s, e));

    int best_time = celeb_density(schedule);
    std::cout << "Best time to attend party is from " << best_time << " to " << best_time + 1 << "n";

Right or wrong: Did you celebrate your birthday at least once in prison?

Report abuse

more details