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.
- Goodland Electricity
- Discussions
Goodland Electricity
Goodland Electricity
Sort by
recency
|
50 Discussions
|
Please Login in order to post a comment
Java
C#:
My approach for this was essentially: given a city position, find the optimal point to place a power plant for that city position. Once I find a place for it, move to the furthest out city position not covered by the power plant I just placed, and do that again. Continue doing that until I reach the end of the array.
To find the optimal position for a given city, I use the k value to go as far out as possible (taking care to remain in-bounds of the array). I check if the position can contain a power plant. If it can, I use that position. If not, I reduce the value by one and continue. The lowest value is the previously placed power plant + 1 (or 0 if none has been placed yet).
Hey, someone can explain why sample test case 2's answer is "3"?
10 3 0 1 0 0 0 1 1 1 1 1
The range is 3 so it answer seems 2.
0 1 0 0| 0 1 1 1| 1 1
include
include
using namespace std;
int pylons(int k, const vector& arr) { int need_power = 0; int count = 0;
}
int main() { int n, k; cin >> n >> k;
}