搜狗笔试nlogn为什么超时啊?
大佬们帮忙看看 二分法查找对角线最近的一个点,为什么超时 int main(){ int N; while (cin >> N){ vector<double> angle; double temp; for (int i = 0; i<N; i++){ cin >> temp; angle.push_back(temp); } if (N == 0 || N == 1) cout << 0.00000000 << endl; else{ double maxlen = 0, len = 0; int index = 0; if (angle[N - 1] - angle[0] <= 180.0) cout << setprecision(8) << angle[N - 1] - angle[0] << endl; else{ for (int i = 0; i<N && angle[i] < 180; i++){ double midangle = angle[i] + 180.0; int index = 0; int low = 0, high = N - 1, mid = 0; while (low <= high){ mid = (low + high) / 2; if (angle[mid] == midangle){ index = mid; break; } else if (angle[mid] < midangle) low = mid + 1; else high = mid - 1; } index = mid; len = (angle[index] - angle[i]) < 180 ? angle[index] - angle[i] : 360 - (angle[index] - angle[i]); maxlen = max(maxlen, len); } cout << setprecision(8) << maxlen << endl; } } } return 0; }
#搜狗#