l4u5son6 @ 2024-07-10 14:48:47
rtrtrtrtrt
#include<bits/stdc++.h>
using namespace std;
int a[10005];
int main()
{
int n, k;
cin>>n>>k;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
bool f;
for(int i=1;i<=n-1;i++)
{
f=true;
for(int j=1;j<=n-1;j++)
{
if(a[j]>a[j+1])
{
swap(a[j],a[j+1]);
f=false;
}
}
if(f) break;
}
cout<<a[k-1];
return 0;
}
by a18981826590 @ 2024-07-10 14:52:43
@l4u5son6
数组大小
求关
by l4u5son6 @ 2024-07-10 14:57:25
@a18981826590 现在TLE了
by a18981826590 @ 2024-07-10 15:02:08
@l4u5son6
别用冒泡排序,去学习新算法,比如归并排序
by l4u5son6 @ 2024-07-10 15:08:21
过了
虽然用了STL
by a18981826590 @ 2024-07-10 15:26:13
@l4u5son6
#include<iostream>
int a[1000001],b[1000001],m,n;
inline int read(){
int b=0;
char c;
c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)){
b*=10;
b+=c-48;
c=getchar();
}
return b;
}
void print(int d){
if(d<0){
putchar('-');
d=-d;
}
if(d<10){
putchar(d^48);
return;
}
print(d/10);
putchar((d%10)^48);
}
void sort(int x,int y){
int i=x,j=(x+y)/2+1,k=0;
if(x>=y) return;
sort(x,j-1);
sort(j,y);
while(i<=(x+y)/2&&j<=y){
if(a[i]<=a[j]){
b[k]=a[i];
i++;
}
else if(a[i]>a[j]){
b[k]=a[j];
j++;
}
k++;
}
if(i<=(x+y)/2){
for(int l=i;l<=(x+y)/2;l++){
b[k]=a[l];
k++;
}
}
else if(j<=y){
for(int l=j;l<=y;l++){
b[k]=a[l];
k++;
}
}
for(int l=0;l<k;l++) a[x+l]=b[l];
}
int main(){
n=read();
m=read();
for(int i=0;i<n;i++) a[i]=read();
sort(0,n-1);
print(a[m]);
}
归并排序