这个帖子显示 他错的第1个数据,正确输出是5位。
http://www.rqnoj.cn/Status_Show.asp?SID=182361
我这个。。。。答案是-21的。。。是不是数据错了?
接下来是我超级恶心的程序:124行。。。
program li;
var n:longint;
ans1,ans2:ansistring;
map:array[0..31,0..31] of longint;
s:array[1..2] of ansistring;
procedure init;
var i,j:longint;
begin
readln(n);
for i:=1 to n do
for j:=1 to n do read(map[i,j]);
s[1]:=’0’; s[2]:=’0’;
end;
function jiafa(s1,s2:ansistring):ansistring;
var i,j,k:longint;
a,b,c:array[0..300] of longint;
begin
fillchar(a,sizeof(a),0);
fillchar(b,sizeof(b),0);
fillchar(c,sizeof(c),0);
a[0]:=length(s1);
for i:=1 to a[0] do a[a[0]-i+1]:=ord(s1[i])-48;
b[0]:=length(s2);
for i:=1 to b[0] do b[b[0]-i+1]:=ord(s2[i])-48;
if a[0]>b[0] then c[0]:=a[0] else c[0]:=b[0];
for i:=1 to c[0] do
c[i]:=a[i]+b[i];
for i:=1 to c[0] do begin c[i+1]:=c[i+1]+c[i] div 10; c[i]:=c[i] mod 10; end;
for i:=c[0]+2 downto 1 do if c[i]<>0 then begin c[0]:=i; break; end;
jiafa:=’’;
for i:=1 to c[0] do jiafa:=chr(c[i]+48)+jiafa;
end;
function chengfa(s1,s2:ansistring):ansistring;
var i,j,k:longint;
a,b,c:array[0..300] of longint;
begin
fillchar(a,sizeof(a),0);
fillchar(b,sizeof(b),0);
fillchar(c,sizeof(c),0);
a[0]:=length(s1);
for i:=1 to a[0] do a[a[0]-i+1]:=ord(s1[i])-48;
b[0]:=length(s2);
for i:=1 to b[0] do b[b[0]-i+1]:=ord(s2[i])-48;
c[0]:=a[0]+b[0]+1;
for i:=1 to a[0] do
for j:=1 to b[0] do c[i+j-1]:=c[i+j-1]+a[i]*b[j];
for i:=1 to c[0] do begin c[i+1]:=c[i+1]+c[i] div 10; c[i]:=c[i] mod 10; end;
for i:=c[0]+2 downto 1 do if c[i]<>0 then begin c[0]:=i; break; end;
chengfa:=’’;
for i:=1 to c[0] do chengfa:=chr(c[i]+48)+chengfa;
end;
function jianfa(s1,s2:ansistring):ansistring;
var i,j,k,t:longint; s3:ansistring;
a,b,c:array[0..300] of longint;
begin
t:=1;
if length(s1)<length(s2) then begin s3:=s1; s1:=s2; s2:=s3; t:=-1; end;
if length(s1)=length(s2) then
begin
i:=1;
while s1[i]=s2[i] do inc(i);
if s2[i]>s1[i] then begin s3:=s1; s1:=s2; s2:=s3; t:=-1; end;
end;
a[0]:=length(s1);
for i:=1 to a[0] do a[a[0]-i+1]:=ord(s1[i])-48;
b[0]:=length(s2);
for i:=1 to b[0] do b[b[0]-i+1]:=ord(s2[i])-48;
c[0]:=a[0];
for i:=1 to c[0] do c[i]:=a[i]-b[i];
for i:=1 to c[0] do
if c[i]<0 then
begin dec(c[i+1]); c[i]:=c[i]+10; end;
for i:=c[0]+2 downto 1 do if c[i]<>0 then begin c[0]:=i; break; end;
jianfa:=’’;
for i:=1 to c[0] do jianfa:=chr(c[i]+48)+jianfa;
if t=-1 then jianfa:=’-’+jianfa;
while (jianfa[1]=’0’) and (length(jianfa)>1) do jianfa:=copy(jianfa,1,length(jianfa));
end;
procedure work(x,y,z:longint);
var j,k,t:longint; ss,i:ansistring;
begin
t:=0; i:=’1’;
while t<n do
begin
if x>n then x:=1;
if y>n then y:=1;
if x<1 then x:=n;
inc(t);
ss:=’’;
j:=1;
while j<=map[x,y] do j:=j*10; j:=j div 10; k:=map[x,y];
while j>0 do
begin
ss:=chr(k div j+48)+ss;
k:=k-k div j *j;
j:=j div 10;
end;
i:=chengfa(i,ss);
if z=1 then begin inc(x); inc(y); end else
begin dec(x); inc(y); end;
end;
s[z]:=jiafa(s[z],i);
end;
procedure doit;
var i:longint;
begin
if n=2 then writeln(map[1,1]*map[2,2]-map[1,2]*map[2,1]);
for i:=1 to n do work(i,1,1);
for i:=1 to n do work(i,1,2);
writeln(jianfa(s[1],s[2]));
end;
begin
init;
doit;
end.