C++3个TLE求助
查看原帖
C++3个TLE求助
1048193
PengDave楼主2023/9/27 20:58

时间复杂度O(n^2)

#include<iostream>
//#include<algorithm>
using namespace std;
/*bool cmp(int a,int b){
    return a>b;
}*/
void psort(int a[],int len){
    for(int j=len-1;j>0;j--){
        bool flag=true;
        if(a[j+1]>a[j]){
            swap(a[j+1],a[j]);
            flag=0;
        }
        if(flag)    break;
    }
}
int main(){
    ios::sync_with_stdio(false);
    int s[100001];
    int n,w,h=1;
    cin>>n>>w;
    for(int i=1;i<=n;i++){
        cin>>s[i];
        int t=i*w*1.0/100;
        int p=max(1,t);
        //sort(s+1,s+i+1,cmp);
        psort(s,i);
        cout<<s[p]<<" ";
    }
    return 0;
}
2023/9/27 20:58
加载中...