讨论 / 猪王争霸 找错误
c3 2011-04-21 00:54:00
点我顶贴 收藏 删除
var a:array[1..1000] of ansistring;

b:array[1..1000] of string;

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

n,i,j:longint;

s:ansistring;

begin

readln(n);

for i:=1 to n do

begin

readln(b[i]);

readln(a[i]);

end;

for i:=1 to n-1 do

for j:=n-1 downto 1 do

if (length(a[j])<length(a[j+1]))or

(length(a[j])=length(a[j+1]))and(a[j]<a[j+1])or

(a[j]=a[j+1])and(b[j]>b[j+1]) then

begin

s:=a[j];a[j]:=a[j+1];a[j+1]:=s;

s:=b[j];b[j]:=b[j+1];b[j+1]:=s;

end;

for i:=1 to n do

writeln(b[i]);

for i:=1 to n do

a[i]:=copy(a[i],length(a[i])-489,490);

for i:=1 to n do

for j:=1 to length(a[i]) do

c[j]:=c[j]+ord(a[i][length(a[i])+1-j])-48;

for i:=1 to 490 do

begin

c[i+1]:=c[i+1]+c[i] div 10;

c[i]:=c[i] mod 10;

end;

for i:=490 downto 1 do

write(c[i]);

end.

测试点5,6,7,8,9,10错了

#1 noip2012@2010-10-18 03:44:00
回复 删除
暂时没看出你的错误,不过有些地方最好按比较不容易错的来写,比如这里的排序写成选排可能好些,要是因为这个丢分不太值得

下面是我的代码,虽然丑,但起码能AC

var

t,ans:array[1..2000] of longint;

num,nam:array[1..1000] of ansistring;

n,i,j:longint;

procedure swap(x,y:longint);

var

tmp:ansistring;

begin

tmp:=num[x];

num[x]:=num[y];

num[y]:=tmp;

tmp:=nam[x];

nam[x]:=nam[y];

nam[y]:=tmp;

end;

begin

readln(n);

for i:=1 to n do

begin

readln(nam[i]);

readln(num[i]);

end;

for i:=1 to n-1 do

for j:=i+1 to n do

if ((length(num[i])<length(num[j]))or((length(num[i])=length(num[j]))and(num[i]<num[j])))or

((num[i]=num[j])and(nam[i]>nam[j])) then swap(i,j);

for i:=1 to n do writeln(nam[i]);

for i:=1 to n do

begin

nam[i]:=copy(nam[i],length(nam[i])-489,490);

num[i]:=copy(num[i],length(num[i])-489,490);

end;

fillchar(ans,sizeof(ans),0);

for i:=1 to n do

begin

fillchar(t,sizeof(t),0);

for j:=1 to length(num[i]) do t[j]:=ord(num[i,length(num[i])+1-j])-48;

for j:=1 to 490 do

begin

inc(ans[j],t[j]);

if j<>490 then inc(ans[j+1],ans[j] div 10);

ans[j]:=ans[j] mod 10;

end;

end;

for i:=490 downto 1 do write(ans[i]);

writeln;

end.

#2 c3@2010-10-22 06:08:00
回复 删除
终于找到自己的错误了

经过思考终于找到自己的错误了

在这里也提醒一下大家

你看题目里写的是1000个猪王,即n<=1000;

数据里的n竟然有几个数据是>1000的

n估计大概<10000

所以数组最好开10000

#3 乙酸@2010-11-13 08:35:00
回复 删除
回复 板凳c3 的帖子

我刚过了,没有的事。

#4 opiece@2011-04-17 21:59:00
回复 删除
我也过了,(*^__^*) 嘻嘻……

var

i,j,m,n,k,len,la,lb,lc,x:longint;

sn,s:array[1..100000] of ansistring;

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

p:ansistring;

begin

readln(n);

for i:=1 to n do

begin

readln(sn[i]);

readln(s[i]);

end;

for i:=1 to n-1 do

for j:=i+1 to n do

if (length(s[i])<length(s[j]))

or(length(s[i])=length(s[j]))and(s[i]<s[j])

or(length(s[i])=length(s[j]))and((s[i]=s[j])and(sn[i]>sn[j])) then

begin

p:=sn[i]; sn[i]:=sn[j]; sn[j]:=p;

p:=s[i]; s[i]:=s[j]; s[j]:=p;

end;

for i:=1 to n do

begin

la:=length(s[i]);

fillchar(a,sizeof(a),0);

for j:=1 to la do a[la+1-j]:=ord(s[i][j])-ord('0');

k:=1; x:=0;

while (k<=la) or (k<=lb) do

begin

b[k]:=a[k]+b[k]+x;

x:=b[k] div 10;

b[k]:=b[k] mod 10;

inc(k);

end;

if x>0 then begin lb:=k; b[k]:=x; end

else lb:=k-1;

end;

for i:=1 to n do

writeln(sn[i]);

for i:=490 downto 1 do

write(b[i]);

end.

#5 zhangzhan456@2011-04-21 00:54:00
回复 删除
这样也行

状态: Accepted

测评机: Xeost[5]

得分: 100分

提交日期: 2011-4-21 15:53:00

有效耗时: 3547毫秒

测试结果1: 通过本测试点|有效耗时172ms

测试结果2: 通过本测试点|有效耗时156ms

测试结果3: 通过本测试点|有效耗时250ms

测试结果4: 通过本测试点|有效耗时188ms

测试结果5: 通过本测试点|有效耗时687ms

测试结果6: 通过本测试点|有效耗时594ms

测试结果7: 通过本测试点|有效耗时63ms

测试结果8: 通过本测试点|有效耗时390ms

测试结果9: 通过本测试点|有效耗时844ms

测试结果10: 通过本测试点|有效耗时203ms

提交代码: view sourceprint?01.program jiji;

02.type num=array[0..1002] of int64;

03.var

04.a:array[0..1002] of ansistring;

05.p:array[0..1002] of num;

06.sum:num;

07.n,i,j,k,x,y,t:longint; s:ansistring; ch:char;

08.function big(x,y:integer):integer;

09.var i:longint;

10.begin

11.if p[x,0]>p[y,0] then exit(1);

12.if p[x,0]<p[y,0] then exit(2);

13.for i:=p[x,0] downto 1 do

14.begin

15.if p[x,i]>p[y,i] then exit(1);

16.if p[x,i]<p[y,i] then exit(2);

17.end;

18.exit(0);

19.end;

20.begin

21.readln(n);

22.for j:=1 to n do

23.begin

24.readln(a[j]);

25.readln(s);k:=1;t:=1;

26.for i:=length(s) downto 1 do

27.begin

28.if k=10000000 then begin k:=1;inc(t); end;

29.inc(p[j,t],k*(ord(s[i])-48));

30.k:=k*10;

31.end;

32.p[j,0]:=t;

33.end;

34.for i:=1 to n do

35.for j:=i+1 to n do

36.if (big(i,j)=2)or((big(i,j)=0) and (a[i]>a[j]))

37.then

38.begin

39.a[0]:=a[i];a[i]:=a[j];a[j]:=a[0];

40.p[0]:=p[i];p[i]:=p[j];p[j]:=p[0];

41.end;

42.for i:=1 to n do

43.for j:=1 to 70 do inc(sum[j],p[i,j]);

44.for i:=1 to 70 do begin inc(sum[i+1],sum[i] div 10000000);

45.sum[i]:=sum[i] mod 10000000;

46.end;

47.for i:=1 to n do writeln(a[i]);

48.for i:=70 downto 1 do

49.begin

50.if sum[i]<1000000 then write(0);

51.if sum[i]<100000 then write(0);

52.if sum[i]<10000 then write(0);

53.if sum[i]<1000 then write(0);

54.if sum[i]<100 then write(0);

55.if sum[i]<10 then write(0);

56.write(sum[i]);

57.end;

58.writeln;

59.end.

查看更多回复
提交回复