| Run ID | 作者 | 问题 | 语言 | 测评结果 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 91830 | sh25_shenpy | 蚂蚁感冒 | C++ | 通过 | 0 MS | 256 KB | 987 | 2026-06-17 06:56:38 |
#include <iostream> #include <vector> #include <cmath> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; int sick = a[0]; int p = abs(sick); // 感冒蚂蚁位置 bool right = sick > 0; // 方向:右true,左false int left_right = 0; // 左边向右 int right_left = 0; // 右边向左 for (int x : a) { int pos = abs(x); if (x == sick) continue; if (right) { // 感冒蚂蚁向右 if (pos < p && x > 0) left_right++; if (pos > p && x < 0) right_left++; } else { // 感冒蚂蚁向左 if (pos < p && x > 0) left_right++; if (pos > p && x < 0) right_left++; } } if (left_right + right_left == 0) cout << 1 << endl; else cout << 1 + left_right + right_left << endl; return 0; }