讨论 / 为什么我只有70分?
春天的蛋 2008-06-03 22:59:00
点我顶贴 收藏 删除
program count;

var

a:array[1..200000] of longint;

b,c:array[1..10000] of longint;

n,i,y:longint;

procedure sort(s,t:longint);

var

i,j,m,r,x:longint;

begin

randomize;

r:=random(s-t+1)+t;

m:=a[r];a[r]:=a[s];a[s]:=m;

i:=s;j:=t;x:=a[i];

repeat

while (i<j) and (a[j]>=x) do j:=j-1;

if i<j then begin a[i]:=a[j];i:=i+1;end;

while (i<j) and (a[i]<=x) do i:=i+1;

if i<j then begin a[j]:=a[i];j:=j-1;end;

until i=j;

a[i]:=x;

i:=i+1;

j:=j-1;

if i<t then sort(i,t);

if s<j then sort(s,j);

end;

begin

readln(n);

for i:=1 to n do read(a[i]);

sort(1,n);

b[1]:=a[1];

y:=1;

for i:=1 to 10000 do c[i]:=1;

for i:=2 to n do if a[i]<>a[i-1] then begin

y:=y+1;

b[y]:=a[i];

end else c[y]:=c[y]+1;

for i:=1 to y do begin write(b[i], ,c[i]);writeln;end;

end.

这是我的程序,请牛们帮我检查一下或者运行一下,谢谢!

#1 ssxyh@2008-02-10 02:15:00
回复 删除
肯定超时!~数据这么大,不处理直接快排会超.
#2 gaoxin@2008-02-10 04:30:00
回复 删除
直接快排不会超,程序也好象没问题,就是快排有点怪,我们用的好象和你的不一样,还有统计个数不用那么复杂,只要每个和前一个比较,相同的话个数就加一,不同就输出,这样就可以了
#3 3144046cjc@2008-02-10 05:16:00
回复 删除
快排那里有问题,去free pascal目录下的demo\text\qsort里看看标准的快排吧。我在noip的时候就直接复制。快排其实是很容易出错的!
#4 春天的蛋@2008-02-10 22:39:00
回复 删除
我看咯,那是取中吧,这个快排是我们老师教我们

的。说是最好的。。。

#5 lry_conan@2008-05-13 06:09:00
回复 删除
传说中的随机化快排。。。。。。
#6 Cynical@2008-06-03 22:59:00
回复 删除
const max=200002;

var a:array[-1..max] of int64;

i,j,n:longint;

procedure qsort(l,r:int64);

var i,j,k,t:int64;

begin

i:=l;

j:=r;

k:=a[(i+j) div 2];

repeat

while a[i]<k do

inc(i);

while a[j]>k do

dec(j);

if i<=j then

begin

t:=a[i];

a[i]:=a[j];

a[j]:=t;

inc(i);

dec(j);

end;

until i>j;

if i<r then qsort(i,r);

if l<j then qsort(l,j);

end;

begin

readln(n);

for i:=1 to n do

readln(a[i]);

qsort(1,n);

for i:=1 to n do

begin

if a[i]<>a[i+1] then

begin

writeln(a[i], ,j+1);

j:=0;

end

else

inc(j);

end;

end.

事实上很简单的···

是快排的问题啦

查看更多回复
提交回复