https://codeforces.com/contest/1808/problem/C
时间: 2023-10-01 07:07:14 浏览: 121
这里有2008年C语言试题
Solution:
Observations:
- If we put a 1 at a particular position, we can't put 1's at positions adjacent to it.
- If there are 'x' 1's in the grid, they must be placed in a way that every 2 1's must have at least 1 0 between them. Otherwise, we can't make the required number of moves.
- If we have a grid of size n x n, then we need at least (n+1)/2 1's to make the required moves.
Approach:
- We can fill the grid diagonally with 1's until we reach the last diagonal that has only one cell.
- If the number of 1's filled is less than (n+1)/2, then we fill in the remaining cells with 0's.
- If the number of 1's filled is greater than (n+1)/2, then we remove the excess 1's starting from the last diagonal.
Time Complexity: O(n^2)
Space Complexity: O(n^2)
Let's see the implementation.
阅读全文