#include <bits/stdc++.h> using namespace std; // bugs存放位置i下的初始虫子速度 int bugs[120]; // lefts是在速度为0的虫子左边的向右移动的虫子下标索引数组 vector<int> lefts; // rights是在速度为0的虫子右边的向左移动的虫子下标索引数组 vector<int> rights; int main() { int n, flag; cin >> n; int pos, speed; for(int i=0; i<n; i++){ cin >> pos >> speed; if(speed == 0) flag = pos; bugs[pos] = speed; } int i, numLeft = 0, numRight = 0; // 统计在速度为0的虫子左右分别有多少个向速度为0的虫子移动的虫子 for(i=1; i<=99; i++){ if(i == flag){ break; } if(bugs[i] == 1) { numLeft++; lefts.push_back(i); } } for(i++; i<=99; i++){ if(bugs[i] == -1) { numRight++; rights.push_back(i); } } // 根据分析,如果左右虫子数量相等,那么最终速度为0的虫子还是会停留在原始位置,不会掉下去 if(numLeft == numRight) cout << "Cannot fall!"; // 如果左边虫子比右边虫子多,那么最靠速度为0的虫子的多出来的那个左边的虫子,最终会和其相撞,并使它向右移动 else if(numLeft > numRight){ pos = lefts[lefts.size() - numRight - 1]; cout << 100 - pos; }else { //右边也容易考虑 pos = rights[numLeft]; cout << pos; } return 0; }