题解:P17413 「IXOI R3」时间复杂度分析

· · 题解

这题是一道非常好的训练分支结构的题目。
题目意思就是输入一个数看那个复杂度可以让这个数过,因为评测机是 1 秒 5\times10^{8} 所以我们就能判断了。
如果 n>5\times10^{8} 呢么只能 O(1),如果 n\le5\times10^{8} 但是 n^2>5\times10^{8} 那么就只能 O(n),其他的就是可以 O(n^2),但 n 很大要开 long long。

AC 代码

#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a;
    cin>>a;
    if(a>5e8){
        cout<<"O(1)";
    }else if(a<=5e8&&a*a>5e8){
        cout<<"O(n)";
    }else{
        cout<<"O(n^2)";
    }
    return 0;
}