535 条题解
-
0Plam_gxy LV 10 @ 2009-10-29 21:46:53
堆果然快!!!
建一个小根堆然后每次取根节点&根节点的左儿子和右儿子比较小的.
不断更新小根堆就可以啦!!!!
program fruit;var h:array[0..20000]of int64; n,i,tot:longint; procedure hpup(k:longint); var i,temp:longint; begin while k>1 do begin i:=k shr 1; if h[k] -
02009-10-29 21:19:22@
var
n,i,j,s,t:longint;
a:array[1..1000]of integer;
begin
readln(n);
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:=2 to n do
a[i]:=a+a[i];
for i:=2 to n do
s:=s+a[i];
writeln(s);
end. -
02009-10-29 16:30:23@
var
n,i,j,s,t:longint;
a:array[1..1000]of integer;
begin
readln(n);
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:=2 to n do
a[i]:=a+a[i];
for i:=2 to n do
s:=s+a[i];
writeln(s);
end. -
02009-10-27 21:35:50@
var
ans:int64;
n:longint;
a:array[0..10000] of longint;procedure qsort(l,r:longint);
var
i,j,m:longint;
begin
i:=l;j:=r;m:=a[(i+j) div 2];
repeat
while a[i]m do dec(j);
if ij;
if l -
02009-10-26 21:21:04@
├ 测试数据 01:运行超时...
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 103ms
├ 测试数据 06:答案正确... 244ms
├ 测试数据 07:运行超时...
├ 测试数据 08:运行超时...
├ 测试数据 09:运行超时...
├ 测试数据 10:运行超时
无语....... -
02009-10-26 19:25:24@
这题队列的数组记得要使用Longint,否则就会30分。
楼下:哈弗曼可以的!
-
02009-10-26 19:20:00@
这题哈夫曼绝对不行。。。。
-
02009-10-23 21:46:00@
讨厌的堆
总算秒杀了 -
02009-10-23 13:50:58@
const max=10000;
var i,j,n,t,t2,k,t3,t4:longint;
a:array[0..max] of longint;
begin
readln(n);t2:=0;
for i:=1 to n do
read(a[i]);
for i:=2 to n do
begin
j:=i;
a[0]:=a[i];
while a[j-1]>a[0] do
begin
a[j]:=a[j-1];
j:=j-1;
end;
a[j]:=a[0];
end;
for i:=2 to n do
begin
t:=a+a[i];j:=i;t2:=t+t2;
while (t>a[j+1])and(j -
02009-10-22 20:39:47@
#include
using namespace std;
int n,a[10001],s=0;
void sift(int x)
{
int p,temp;
while(x=1;i--)
sift(i);
for (i=1;i -
02009-10-18 15:25:51@
基础堆排序复习
var
a:array[1..20000]of longint;
i,j,b,c,n,num,h:longint;
procedure insert(x:longint);
var temp,i:longint;
begin
inc(h);
a[h]:=x;
i:=h;
while (i>1)and(a[i]1 do
begin
c:=delete;
b:=delete;
insert(c+b);
inc(num,b+c);
end;
writeln(num);
end. -
02009-10-17 21:11:30@
快排加插入,搞定
var a,b:array[0..10001] of longint;
s,n,i,j:longint;
procedure qs(l,r:longint);
var t,m,j,i:longint;
begin
j:=r; i:=l;
m:=a[(i+j) div 2];
repeat
while a[i]m do dec(j);
if ij;
if il then qs(l,j);
end;
procedure cha(l,r,k:longint);
var i,j:longint;
begin
for j:=l-1 to r-1 do
a[j]:=a[j+1];
a[r]:=0;
if k>a[r-1] then begin a[r]:=k; exit; end;
for i:=l-1 to r-1 do
if ((k>a[i]) and ((k -
02009-10-15 22:14:34@
选择排序
编译通过...
├ 测试数据 01:运行超时...
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 275ms
├ 测试数据 04:答案正确... 416ms
├ 测试数据 05:运行超时...
├ 测试数据 06:运行超时...
├ 测试数据 07:运行超时...
├ 测试数据 08:运行超时...
├ 测试数据 09:运行超时...
├ 测试数据 10:运行超时...
---|---|---|---|---|---|---|---|-
Unaccepted 有效得分:30 有效耗时:691ms___|\__|\__|\__|\__|\__|\__|\__|\__|\__|\__|\__|\__|\__|\__|\__|\__|\___|_
修改以后
编译通过...
├ 测试数据 01:答案正确... 369ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案正确... 9ms
├ 测试数据 06:答案正确... 25ms
├ 测试数据 07:答案正确... 400ms
├ 测试数据 08:答案正确... 447ms
├ 测试数据 09:答案正确... 384ms
├ 测试数据 10:答案正确... 400ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:2034msvar i,j,k,n,m,js:longint;
a,b:array[0..20001]of longint;
begin
read(n);
for i:=1 to n do read(a[i]);
m:=n;
for i:=1 to n-1 do
for j:=i+1 to n do
begin
if a[i]>a[j] then
begin
k:=a[i];
a[i]:=a[j];
a[j]:=k;
end;
end;
js:=1;
while m>1 do
begin
b[js]:=a[js]+a[js+1];
a[js]:=0;
i:=js+1;
while (a[i] -
02009-10-15 13:12:44@
program Project1;
const max=10000;
var i,j,n,t,t2,k,t3,t4:longint;
a:array[0..max] of longint;
begin
readln(n);t2:=0;
for i:=1 to n do
read(a[i]);
for i:=2 to n do
begin
j:=i;
a[0]:=a[i];
while a[j-1]>a[0] do
begin
a[j]:=a[j-1];
j:=j-1;
end;
a[j]:=a[0];
end;
for i:=2 to n do
begin
t:=a+a[i];j:=i;t2:=t+t2;
while (t>a[j+1])and(j -
02009-10-14 21:55:05@
program fruit;
type
myarray=array [1..10000] of longint;
tqueue=record
data: myarray;
f,r: integer;
end;
var
q1,q2:tqueue;
i,n:integer;
total,x:longint;procedure quicksort(var a:myarray;s,t:integer);
var
i,j,x:longint;
begin
i:=s;j:=t;x:=a;
while i=x) and (j>i) do dec(j);
if j>i then begin a[i]:=a[j]; inc(i); end;
while (a[i] -
02009-10-11 21:01:17@
program f;
const
inf='f.in';
ouf='f.out';
var
a,b,c:longint;
begin
assign(input,inf);
reset(input);
assign(output,ouf);
rewrite(output);
readln(a,b);
c:=a+b;
writeln(c);
close(input);
close(output);
end. -
02009-10-11 15:38:11@
program sdfs;
var
a,b:array[0..100000]of longint;
i,j,ah,n,aw,bh,bw:longint;
s:cardinal;
procedure pp(l,r:longint);
var
i,j,x:longint;
begin
i:=l;
j:=r;
x:=a[i];
while i -
02009-10-11 01:22:25@
acm风格,简单到底
#include
#include
using namespace std;
priority_queue q;int main(){
int n,x;
scanf("%d",&n);
for (;n--;q.push(x))
scanf("%d",&x);for(x=0;!q.empty();q.push(n)){
n=q.top(); q.pop();
if(q.empty())break;
n+=q.top(); q.pop();
x+=n;
}
printf("%d",x);
return 0;
} -
02009-10-10 21:02:56@
请用鼠标拖动选择下列文字即可显示题解
var n,i,j,min1,min2:integer; ans:int64; a:array [0..10000] of int64;begin ans:=0; a[0]:=9223372036854775807; readln(n); for i:=1 to n do read(a[i]); readln; if n=1 then begin writeln(0); halt; end; for i:=1 to n-1 do begin min1:=0; min2:=0; for j:=1 to n do if a[j]-1 then begin if a[j] -
02009-10-10 18:41:37@
太悲哀了,这已经是我第n次把heapsort写挂了。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。