Untitled
unknown
plain_text
a year ago
1.2 kB
1
Indexable
Never
#include <iostream> #include <vector> using namespace std; int main() { int n = 3; vector<pair<int, int>> dirtyCells; string status = "dcdcdcdcd"; // 'd' represents dirty, 'c' represents clean int currentPosition = 0; // Starting position of the vacuum cleaner // Identify dirty cells for (int i = 0; i < n * n; i++) { if (status[i] == 'd') { dirtyCells.emplace_back(i / n + 1, i % n + 1); } } // Simulate the cleaning process for (const auto& dirtyCell : dirtyCells) { int targetPosition = dirtyCell.first * n + dirtyCell.second - 1; // Move the vacuum cleaner left or right while (currentPosition != targetPosition) { if (currentPosition < targetPosition) { cout << "Move right" << endl; currentPosition++; } else { cout << "Move left" << endl; currentPosition--; } } // Clean the cell cout << "Clean cell at position (" << dirtyCell.first << ", " << dirtyCell.second << ")" << endl; status[targetPosition] = 'c'; } return 0; }