这道题看起来是分支结构,实则就是。
注意一下这里是 找到最高的复杂度 ,所以我们要先考虑 ,再去考虑 ,最后是 。 对于 的情况,我们可以使用开根函数来找到这个最大值。
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n;
cin>>n;
if(n<=sqrt(500000000)) cout<<"O(n^2)";
else if(n<=500000000) cout<<"O(n)";
else cout<<"O(1)";
}