- 第k大
- 2013-08-26 16:25:02 @
var n,k,i,t,j:integer;
fs:array[1..100000] of integer;
begin
readln(n,k);
for i:=1 to n do readln(fs[i]);
for i:=1 to n do
for j:=i+1 to n do
if fs[i]<fs[j] then begin t:=fs[i]; fs[i]:=fs[j]; fs[j]:=t; end;
writeln(fs[k]);
end.
为啥W0?
5 条评论
-
cwoj LV 8 @ 2016-08-15 12:25:39
评测状态 Accepted
题目 P1788 第k大
递交时间 2016-08-15 12:22:20
代码语言 C++
评测机 ShadowShore
消耗时间 421 ms
消耗内存 956 KiB
评测时间 2016-08-15 12:22:22评测结果
编译成功
测试数据 #0: Accepted, time = 0 ms, mem = 952 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 952 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 952 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 952 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 956 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 952 KiB, score = 10
测试数据 #6: Accepted, time = 125 ms, mem = 952 KiB, score = 10
测试数据 #7: Accepted, time = 109 ms, mem = 952 KiB, score = 10
测试数据 #8: Accepted, time = 109 ms, mem = 952 KiB, score = 10
测试数据 #9: Accepted, time = 78 ms, mem = 952 KiB, score = 10
Accepted, time = 421 ms, mem = 956 KiB, score = 100
代码
#include<iostream>
#include<algorithm>
using namespace std;
int n,k;
int score[100001];
int main()
{
cin>>n>>k;
for(int i=0;i<n;i++)
cin>>score[i];
sort(score,score+n,greater<int>());
k--;
cout<<score[k];
return 0;
}
转C++吧,瞬间AC -
2016-04-28 13:52:37@
var n,k,i,t,j:longint; a:array[0..1000000] of longint;
begin
readln(n,k);
for i:=1 to n do
read(a[i]);
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then
begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
end;
for i:=1 to n do
if i=k then writeln(a[i]);
end.
跟你的差不多,就是超时 -
2014-12-20 15:25:03@
血的教训:
输入时要用**read**,否则0分!
此题坑人无数…… -
2013-11-05 16:48:06@
不知道
-
2013-11-01 21:34:38@
你这叫、、、选择排序?
n=100000你这样会超时的、骚年、
- 1