搜索过不去啊!!!!
大牛给个标程吧!!!!!!
╗ ╭╔═╮ ═╗╮╔╮
╚══╠═╝╠══╠═╮╚═╠╩╠╗
║ ║ ║ ║ ║║║║
║ ╯ ║ ╰═║╯║║
║═╮╔══╠═╮╭╝║╮╔╯
╚══╯ ╝ ╰═╝ ╚ ╝╝╯╝
╔══╯═╮
║════║
╔══╔═╗
║ ║ ║
║ ║ ║
╚══╠═╯
状态: Accepted
测评机: Xeost[5]
得分: 100分
提交日期: 2009-1-31 18:05:00
有效耗时: 3468毫秒
测试结果1: 通过本测试点|有效耗时172:ms
测试结果2: 通过本测试点|有效耗时172:ms
测试结果3: 通过本测试点|有效耗时156:ms
测试结果4: 通过本测试点|有效耗时172:ms
测试结果5: 通过本测试点|有效耗时172:ms
测试结果6: 通过本测试点|有效耗时203:ms
测试结果7: 通过本测试点|有效耗时234:ms
测试结果8: 通过本测试点|有效耗时468:ms
测试结果9: 通过本测试点|有效耗时750:ms
测试结果10: 通过本测试点|有效耗时969:ms
提交代码: var a:array[1..20000]of longint;
r,j,i,k:longint;
begin
readln(j);
for i:=1 to j do readln(a[i]);
for i:=1to (j-1)do begin
for k:=(i+1) to j do
if a[i]>a[k] then inc(r);
end;
write(r);
end.
我连优化都没有,如果直接搜索+优化绝对能过。
var
i,j,m,n:longint;
s:array[1..300000]of longint;
begin
m:=0;
read(n);
if n<0 then exit;
for i:=1 to n do readln(s[i]);
for i:=1 to n-1 do
for j:=i+1 to n do
if s[i]>s[j] then inc(m);
write(m);
end.
就这。。。
第一次最后一个点超时了。。。
第二次就过了。。。。
orz...
明明是经典题好吧。。。难道没人写题解嘛。。。。
program p173(input, output);
var
n, i, Sum: longint;
p: array [1..20000] of longint;
temp: array [1..20000] of longint;
procedure msort(left, right: longint);
var
i, l1, l2, middle: longint;
begin
if left < right then
begin
middle := (left + right) shr 1;
msort(left, middle);
msort(middle + 1, right);
l1 := left;
l2 := middle + 1;
for i := left to right do
if ((p[l1] > p[l2]) and (l1 <= middle)) or (l2 > right) then
begin
temp[i] := p[l1];
inc(Sum, right - l2 + 1);
inc(l1)
end
else
begin
temp[i] := p[l2];
inc(l2)
end;
for i := left to right do
p[i] := temp[i]
end
end;
begin
Sum := 0;
fillchar(p, sizeof(p), 0);
readln(n);
for i := 1 to n do
readln(p[i]);
msort(1, n);
writeln(Sum)
end.