zhouyi1227 @ 2020-07-18 17:32:04
求助
#include<bits/stdc++.h>
using namespace std;
int a[5000005];
int main(){
int n,k,t=0;
cin >> n >> k;
for (int i=1;i<=n;i++) cin >> a[i];
sort(a+1,a+n+1);
if (k==0){
cout << a[1];
return 0;
}
for (int i=2;i<=n;i++){
if (a[i+1]!=a[i]) t++;
if (t==k){
cout << a[i];
return 0;
}
}
return 0;
}
by Spasmodic @ 2020-07-18 18:03:29
我正常nth+cin都过不了的说
by Spasmodic @ 2020-07-18 18:04:27
#include<bits/stdc++.h>
using namespace std;
int a[5000005];
int mian(){
int n,k;
scanf("%d%d",&n,&k);
for (int i=1;i<=n;i++)scanf("%d",&a[i]);;
random_shuffle(a+1,a+n+1);
nth_element(a+1,a+k+1,a+n+1);
cout<<a[k+1]<<endl;
return 0;
}
我的代码,已加反抄袭(雾
by Spasmodic @ 2020-07-18 18:05:13
以及这个标题按照3k的标准是极其经典的xxs的说
by Spasmodic @ 2020-07-18 18:06:15
@zhouyi1227
by SIXIANG32 @ 2020-07-18 18:08:17
@happydef 你谷神机过不了惹/kk
by 学而 @ 2020-07-18 18:14:31
重复数字也要计数啊,即使重复数字不计数,你也没有考虑a1=a2的情况
by Spasmodic @ 2020-07-18 18:45:09
@zhouyi1227
#include<bits/stdc++.h>
using namespace std;
struct IO_Tp {
const static int _I_Buffer_Size = 2 << 25;
char _I_Buffer[_I_Buffer_Size], *_I_pos = _I_Buffer;
const static int _O_Buffer_Size = 2 << 25;
char _O_Buffer[_O_Buffer_Size], *_O_pos = _O_Buffer;
IO_Tp() { fread(_I_Buffer, 1, _I_Buffer_Size, stdin); }
~IO_Tp() { fwrite(_O_Buffer, 1, _O_pos - _O_Buffer, stdout); }
IO_Tp &operator>>(int &res) {
while (!isdigit(*_I_pos)) ++_I_pos;
res = *_I_pos++ - '0';
while (isdigit(*_I_pos)) res = res * 10 + (*_I_pos++ - '0');
return *this;
}
IO_Tp &operator<<(int n) {
static char _buf[10];
char *_pos = _buf;
do
*_pos++ = '0' + n % 10;
while (n /= 10);
while (_pos != _buf) *_O_pos++ = *--_pos;
return *this;
}
IO_Tp &operator<<(char ch) {
*_O_pos++ = ch;
return *this;
}
} IO;
int n,k,a[5000005];
int main(){
IO>>n>>k;
for (int i=0;i<n;i++)IO>>a[i];
random_shuffle(a,a+n);
nth_element(a,a+k,a+n);
IO<<a[k];
return 0;
}
实测比时限小一倍
论文鸽txdy!(破音
@SIXIANG
by zhouyi1227 @ 2020-07-19 17:07:56
感谢各位大神,现在搞定了
by jksdijdsic4 @ 2020-07-22 10:28:30
k=k+1
by justinjia @ 2020-08-27 08:09:54
sort能这么用吗?我记得sort只能排序连续自然数序列啊。