2019 Dec Platinum Problem 1 Greedy Pie Eaters
Official Problem StatementEdit
Problem Statement:Edit
Greedy Pie Eaters is a USACO problem that requires you to determine the maximum number of pies that can be eaten by a group of people. The pies are arranged in a circle, and each person can only eat the pies that are directly in front of them.
Solution:Edit
The solution to this problem involves using a greedy algorithm. We can iterate through the pies in the circle, and for each pie, we can check whether the person in front of it has already eaten a pie. If not, we can add one to the total number of pies eaten. This process is repeated until all pies have been checked.
In C++, this can be implemented as follows:
int maxPies(vector<bool> pies) { int count = 0; for (int i = 0; i < pies.size(); i++) { if (!pies[i]) { count++; pies[(i+1) % pies.size()] = true; } } return count; }