Count Press
C++
100% Correct Code ✅
TCS CodeVita Zone 2https://telegram.me/+_hn3cBQVbGliYTI9#include
using namespace std;
https://telegram.me/PLACEMENTLELObool isP(int px, int py, const vector& placementlelo) {
int crossings = 0, vCount = placementlelo.size();
for (int i = 0; i < vCount; ++i) {
int vx1 = placementlelo[i].first, vy1 = placementlelo[i].second;
int vx2 = placementlelo[(i + 1) % vCount].first, vy2 = placementlelo[(i + 1) % vCount].second;
if (((vy1 py)) || ((vy2 py))) {
double intersectX = vx1 + (double)(py - vy1) * (vx2 - vx1) / (vy2 - vy1);
if (intersectX > px) crossings++;
}
}
return (crossings % 2) != 0;
}
https://telegram.me/PLACEMENTLELOint main() {
ios::sync_with_stdio(false);
cin.tie(0);
int vertexCount;
cin >> vertexCount;
vector polygon(vertexCount);
int minX = INT_MAX, maxX = INT_MIN, minY = INT_MAX, maxY = INT_MIN;
https://telegram.me/PLACEMENTLELO for (auto& ver : polygon) {
cin >> ver.first >> ver.second;
minX = min(minX, ver.first);
maxX = max(maxX, ver.first);
minY = min(minY, ver.second);
maxY = max(maxY, ver.second);
}
https://telegram.me/PLACEMENTLELO int blockSize;
cin >> blockSize;
int width = maxX - minX + 1, height = maxY - minY + 1;
vector area(height, vector(width, 0));
for (int y = minY; y < maxY; ++y) {
for (int x = minX; x < maxX; ++x) {
if (isP(x + 0.5, y + 0.5, polygon)) {
area[y - minY][x - minX] = 1;
}
}
}
https://telegram.me/PLACEMENTLELO vector fc;
for (int r = 0; r < height; ++r) {
for (int c = 0; c < width; ++c) {
if (area[r][c] == 1) {
fc.emplace_back(r, c);
}
}
}
https://telegram.me/PLACEMENTLELO sort(fc.begin(), fc.end());
int minA = INT_MAX;
function explore = [&](int currIn, vector& currentGrid, int actionCount) {
if (actionCount >= minA) return;
while (currIn < fc.size() && currentGrid[fc[currIn].first][fc[currIn].second] == 0) {
currIn++;
}
if (currIn == fc.size()) {
minA = min(minA, actionCount);
return;
}
int currentY = fc[currIn].first, currentX = fc[currIn].second;
bool canPlaceBlock = true;
for (int dy = 0; dy < blockSize && canPlaceBlock; dy++) {
for (int dx = 0; dx < blockSize && canPlaceBlock; dx++) {
int newY = currentY + dy, newX = currentX + dx;
if (newY >= height or newX >= width or currentGrid[newY][newX] == 0) {
canPlaceBlock = false;
}
}
}
https://telegram.me/PLACEMENTLELO if (canPlaceBlock) {
vector updatedGrid = currentGrid;
for (int dy = 0; dy < blockSize; dy++) {
for (int dx = 0; dx < blockSize; dx++) {
int newY = currentY + dy, newX = currentX + dx;
if (newY < height && newX < width) updatedGrid[newY][newX] = 0;
}
}
explore(currIn + 1, updatedGrid, actionCount + 1);
}
};
https://telegram.me/PLACEMENTLELO explore(0, area, 0);
cout