We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- C++
- Other Concepts
- Attending Workshops
- Discussions
Attending Workshops
Attending Workshops
Sort by
recency
|
190 Discussions
|
Please Login in order to post a comment
I hope someone doesn't struggle like I did, questioning how in the sample input, workshops 0,1,3 and 5 got selected as the non-overlapping one's.
The challenge editor made a problem and the correct sequence of non-overlapping workshops by start time should be 1, 3, 5 and 8.
Other than that minor correction, everything else works seemlessly.
include
include
include
using namespace std;
struct Workshop { int start_time; int duration; int end_time; };
struct Available_Workshops { int n;
vector workshops; };
Available_Workshops* initialize(int start_time[], int duration[], int n) { Available_Workshops* aw = new Available_Workshops(); aw->n = n; for (int i = 0; i < n; ++i) { Workshop ws; ws.start_time = start_time[i]; ws.duration = duration[i]; ws.end_time = start_time[i] + duration[i]; aw->workshops.push_back(ws); } return aw; }
int CalculateMaxWorkshops(Available_Workshops* ptr) {
}
my solution(cp20++): int main() { int n; cin >> n;
}
My solution:
include
using namespace std;
//Define the structs Workshops and Available_Workshops. struct Workshop { int st; int dur; int et; };
struct Available_Workshops { int n; vector wsarr; };
//Implement the functions initialize and CalculateMaxWorkshops Available_Workshops* initialize(int start_time[], int duration[], int n) { Available_Workshops *ws_avail = new Available_Workshops;
}
int CalculateMaxWorkshops(Available_Workshops* ws_avail) { int cnt = 1; int cur; vector vec;
}
int main(int argc, char argv[]) { int n; // number of workshops cin >> n; // create arrays of unknown size n int start_time = new int[n]; int* duration = new int[n];
}
//try this
include
include
include
using namespace std;
class Workshop { public: int start_time; int end_time;
};
class Available_Workshops { public: vector workshops;
};
Available_Workshops* initialize(int start_time[], int duration[], int n) { vector workshops; for (int i = 0; i < n; i++) { workshops.push_back(Workshop(start_time[i], duration[i])); } Available_Workshops* available_workshops = new Available_Workshops(workshops); return available_workshops; }
int CalculateMaxWorkshops(Available_Workshops* ptr) { vector& workshops = ptr->workshops;
}
int main() { int n; // Number of workshops cin >> n;
}