本文共 2702 字,大约阅读时间需要 9 分钟。
为了解决这个问题,我们需要模拟话筒内部水滴在新的重力方向下的流动情况。我们需要检查是否有水滴会流到关键电子元件上,如果有的话,话筒就会坏掉。
#include#include #include #include #include #define LL long longusing namespace std;int n, m;char c;int x, y;char a[1002][1002];int b[1002][2]; // b[k][0]是i,b[k][1]是jint tot = 0;bool judge = true;void simulate() { if (c == 'v') { // 下方向,水滴向下流动 for (int k = 1; k <= tot; ++k) { int i = b[k][0]; int j = b[k][1]; int di = i + 1; while (di <= n && a[di][j] != 'x') { ++di; } if (a[di][j] == 'x' || di > n) { judge = false; return; } } } else if (c == '^') { // 上方向,水滴向上流动 for (int k = 1; k <= tot; ++k) { int i = b[k][0]; int j = b[k][1]; int di = i - 1; while (di >= 1 && a[di][j] != 'x') { --di; } if (a[di][j] == 'x' || di < 1) { judge = false; return; } } } else if (c == '>') { // 右方向,水滴向右流动 for (int k = 1; k <= tot; ++k) { int i = b[k][0]; int j = b[k][1]; int dj = j + 1; while (dj <= m && a[i][dj] != 'x') { ++dj; } if (a[i][dj] == 'x' || dj > m) { judge = false; return; } } } else if (c == '<') { // 左方向,水滴向左流动 for (int k = 1; k <= tot; ++k) { int i = b[k][0]; int j = b[k][1]; int dj = j - 1; while (dj >= 1 && a[i][dj] != 'x') { --dj; } if (a[i][dj] == 'x' || dj < 1) { judge = false; return; } } }}int main() { cin >> n >> m >> c; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { cin >> a[i][j]; if (a[i][j] == 'o') { tot++; b[tot][0] = i; b[tot][1] = j; } } } if (tot > 0) { simulate(); } if (judge) { cout << "OK" << endl; } else { cout << "GG" << endl; } return 0;}
转载地址:http://wpvoz.baihongyu.com/