|
|
вернуться в форумThere is something very strange about 1068!!! Check this out!!! Послано Ivo 28 май 2001 00:59 I submitted 1068 twice and I always receive "WA" Then I read about the formula and I compared the answers(as you can see down) and they were all the same. Then I submitted the task once again with the the formula and I got "AC". Can someone explain why? var i,sum1,n,sum:longint; begin for n:=-10000 to 10000 do begin {formula} if n < 1 then sum := (( 1 + n) * ( 2 - n)) div 2 else if n >=1 then sum := (( n + 1) * n) div 2; {my solution} sum1:=0; if n=1 then sum1:=1 else if n<=0 then for i:=1 downto n do sum1:=sum1+i else for i:=1 to n do sum1:=sum1+i;
{if there were different answers} if sum<>sum1 then writeln(n,' ',sum1,' ',sum1); readln; end; end. Maybe you got WA with your solution because of your output format > I submitted 1068 twice and I always receive "WA" > Then I read about the formula and I compared the > answers(as you can see down) and they were all > the same. Then I submitted the task once again > with the the formula and I got "AC". Can someone > explain why? > > var i,sum1,n,sum:longint; > begin > for n:=-10000 to 10000 do > begin > {formula} > if n < 1 then sum := (( 1 + n) * ( 2 - n)) div 2 > else if n >=1 then sum := (( n + 1) * n) div 2; > > {my solution} > sum1:=0; > if n=1 then sum1:=1 > else > if n<=0 then > for i:=1 downto n do sum1:=sum1+i > else > for i:=1 to n do sum1:=sum1+i; > > {if there were different answers} > if sum<>sum1 then writeln(n,' ',sum1,' ',sum1); readln; > end; > > end. > What do you mean??? Послано Ivo 29 май 2001 00:07 This is not my output this is a program that compares the two methods of finding the solution if sum<>sum1 then writeln(n,' ',sum1,' ',sum1); i know, but i think your own program have some mistake with the output What mistake??? Tell me more... Послано Ivo 30 май 2001 00:48 > Tong Hop always Vo Dich, and the main reason belongs to ...... the main reson belongs to the server. Maybe some thing wrong with compiling i've submit your solution var i,sum1,n,sum:longint; begin read(n); {my solution} sum1:=0; if n=1 then sum1:=1 else if n<=0 then for i:=1 downto n do sum1:=sum1+i else for i:=1 to n do sum1:=sum1+i;
writeln(sum1);
end. and got WA, but when i change it to var i,sum1,n,sum:longint; begin read(n); {my solution} sum1:=0; if n=1 then sum1:=1 else if n<=0 then (changing in this line) for i:=n to 1 do sum1:=sum1+i else for i:=1 to n do sum1:=sum1+i;
writeln(sum1);
end. And i got AC, i don't know why, but maybe the compiler define that n is always >=1 and it does not run the command "for i:=1 downto n", so u get WA. So that, don't use "downto "when not necessary ! Btw, your program will run slower than any program that use the simple formula. QH@ |
|
|