按时间0.5s增加判断位置 #include <iostream> #include <cmath> using namespace std; int main() { int n; while (cin >> n) { // 注意 while 处理多个 case double list[n][2], t, pos; int k, all = 0; for (int i = 0; i < n; i++) { cin >> list[i][0] >> list[i][1]; if (list[i][1] == 0) { k = i; pos = list[i][0]; } } for (int i = 0; i < n; i++) { if ((list[i][0] - pos)*list[i][1] < 0) { all += list[i][1]; } } if (all == 0) { cout << "Cannot fall!" << endl; } else { for (t = 0; (!( list[k][0] == 100 || list[k][0] == 0)); t += 0.5) { int count = 0; for (int j = 0; j < n; j++) { list[j][0] += list[j][1] * 0.5 ; if (pos == list[j][0]) count++; } for (int i = 0; i < n; i++) { if (count == 3 && list[i][0] == pos) list[i][1] *= -1; else for (int j = i + 1; j < n; j++) { if (list[j][0] == list[i][0]) { int p = list[i][1]; list[i][1] = list[j][1]; list[j][1] = p; } } } } cout << t << endl; } } } // 64 位输出请用 printf("%lld")