336 条题解
-
0zz111 LV 8 @ 2009-05-05 12:49:52
var a,b,s:array[1..10000] of int64;
d,c,i,j,e:longint;
l:int64;
n,m:ansistring;
begin
readln(n);
readln(m);
for i:=1 to length(n) div 4 do val(copy(n,length(n)-4*i+1,4),a[i],e);
for i:=1 to length(m) div 4 do val(copy(m,length(m)-4*i+1,4),b[i],e);
val(copy(n,1,length(n) mod 4),a[length(n) div 4+1],e);
val(copy(m,1,length(m) mod 4),b[length(m) div 4+1],e);
for i:=1 to length(m) div 4+1 do
begin
for j:=1 to length(n) div 4+1 do
begin
c:=i+j-1;
s[c]:=s[c]+b[i]*a[j];
s[c+1]:=s[c+1]+s[c] div 10000;
s[c]:=s[c] mod 10000;
end;
end;
l:=length(n) div 4+length(m) div 4+2;
while s[l]=0 do l:=l-1;
write(s[l]);
for i:=l-1 downto 1 do
begin
d:=1000;
for j:=1 to 4 do
begin
write(s[i] div d);
s[i]:=s[i] mod d;
d:=d div 10;
end;
end;
readln;
end. -
02009-05-03 11:07:56@
if length(s1) mod 4=0 then l1:=length(s1) div 4 elsevsdssssdsdsddddddddddddddddvsdddddddddddffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff l1:=lengthvsvsdvsdvs(s1) div 4+1
weige -
02009-04-29 20:34:07@
const n=10000;
var a,b:array [1..n] of integer;
c:array [1..2*n+1] of longint;
str1,str2:string;
z,e,l1,l2,i,j,x,y,w:integer;
begin
readln(str1);
readln(str2);
l1:=length(str1);
l2:=length(str2);
for i:=l1 downto 1 do
a[l1-i+1]:=ord(str1[i])-ord('0');
for i:= l2 downto 1do
b[l2-i+1]:=ord(str2[i])-ord('0');
fillchar(c,sizeof(c),0);
for i:= 1 to l1 do
for j:=1 to l2 do
begin
x:=a[i]*b[j];
y:=x div 10;
z:=x mod 10;
w:=i+j-1;
c[w]:=c[w]+z;
c[w+1]:=c[w+1]+c[w] div 10+y;
c[w]:=c[w] mod 10;
end;
e:=l1+l2;
if c[e]=0 then e:=e-1;
write(str1,'*',str2,'=');
for i:=e downto 1 do
write(c[i]);
writeln;
end. -
02009-04-26 20:32:20@
各位同学呀,作者道题千万要仔细啊,最后一组数据比10000大,开数组时多开一些否则很惨的。20次AC,悲哀啊。
-
02009-04-20 21:42:35@
两次AC
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms1E9进制高精度
输入输出有点麻烦不知道为什么1E9比1E1快这么多?
program vijos_1040; { 高精度乘法 }
const
maxn=20001;
base=100;
logBase=2;type
baseType=qword;
highInt=record
da:array[1..maxn] of baseType;
len:integer;
end;
highPoint=^highInt;var
a,b,c:highInt;procedure empty(var a:highInt);
begin
with a do
begin
len:=1;
fillchar(da,sizeof(da),0);
end;
end;procedure val(var s:ansistring;var a:highInt);
var
ch:char;
i,j,k:integer;
begin
with a do
begin
while length(s) mod logBase0 do s:='0'+s;
j:=0;
k:=length(s);
while k>0 do
begin
inc(j);
for i:=k-logBase+1 to k do
da[j]:=da[j]*10+ord(s[i])-48;
dec(k,logBase);
end;
len:=j;
end;
end;procedure init;
var
s:ansistring;
po,len:integer;
begin
empty(a);
empty(b);
empty(c);
readln(s);
val(s,a);
readln(s);
val(s,b);
end;procedure highMul(const a,b:highInt;var c:highInt);
var
i,j,l:integer;
begin
empty(c);
for i:=1 to a.len do
for j:=1 to b.len do
begin
inc(c.da,a.da[i]*b.da[j]);
if c.da>=base then
begin
inc(c.da,c.da div base);
c.da:=c.da mod base;
end
end;
l:=a.len+b.len+1;
while (l>0) and (c.da[l]=0) do dec(l);
c.len:=l;
end;procedure print(const a:highInt);
var
i,j:integer;
begin
with a do
for i:=len downto 1 do
begin
if ilen then
for j:=1 to logBase-trunc(ln(da[i])/ln(10))-1 do
write(0);
write(da[i]);
end;
writeln;
end;begin
init;
highMul(a,b,c);
print(c);
end. -
02009-04-15 23:08:23@
program p1040;
var s:ansistring;
a,b,ans:array[1..10000]of longint;
m,n,i,j,k,l,r,tt:longint;procedure print(i:longint);
var j,t:longint;
begin
if (i=k)or(ans[i] div 10000) then write(ans[i])
else
begin
t:=ans[i];
for j:=1 to 4 do
begin
t:=t div 10;
if t=0 then break;
end;
t:=4-j;
for j:=1 to t do write('0');
write(ans[i]);
end;
end;begin
readln(s);
k:=length(s);
m:=0;
i:=1;
while i -
02009-04-13 13:51:59@
楼下那位的能过吗?
-
02009-04-12 16:12:30@
program P_1027;
type
xx=array[0..520]of longint;
var
a,b,c:xx;
s:string;
i:longint;
function cheng(a,b:xx):xx;
var
i,j:longint;
c:xx;
begin
fillchar(c,sizeof(c),0);
c[0]:=a[0]+b[0];
for i:=1 to a[0] do
for j:=1 to b[0] do
begin
c:=a[i]*b[j]+c;
c:=c div 10 +c;
c:=c mod 10;
end;
while (c[0]>1)and(c[c[0]]=0) do dec(c[0]);
cheng:=c;
end;
begin
readln(s);
a[0]:=length(s);
for i:=1 to a[0] do
a[i]:=ord(s[a[0]+1-i])-48;
readln(s);
b[0]:=length(s);
for i:=1 to b[0] do
b[i]:=ord(s[b[0]+1-i])-48;
c:=cheng(a,b);
for i:=c[0] downto 1 do
write(c[i]);
writeln;
end. -
02009-04-08 20:10:58@
var
s1,s2,s3,s:ansistring;
i,j,k1,k2,l1,l2,t1,t2,m,x,y,z,w:longint;
a,b,c:array[1..5000]of longint;
begin
readln(s1);
l1:=length(s1);
k1:=l1;
t1:=1;
while k1>=4 do
begin
s:=copy(s1,k1-3,4);
val(s,m);
a[t1]:=m;
inc(t1);
dec(k1,4);
end;
if l1 mod 40 then begin
s:=copy(s1,1,l1 mod 4);
val(s,m);
a[t1]:=m;
end
else dec(t1);
readln(s2);
l2:=length(s2);
k2:=l2;
t2:=1;
while k2>=4 do
begin
s:=copy(s2,k2-3,4);
val(s,m);
b[t2]:=m;
inc(t2);
dec(k2,4);
end;
if l2 mod 40 then begin
s:=copy(s2,1,l2 mod 4);
val(s,m);
b[t2]:=m;
end
else dec(t2);
for i:=1 to t1 do
for j:=1 to t2 do
begin
x:=a[i]*b[j];
y:=x div 10000;
z:=x mod 10000;
w:=i+j-1;
c[w]:=c[w]+z;
c[w+1]:=c[w+1]+c[w]div 10000+y;
c[w]:=c[w] mod 10000;
end;
m:=t1+t2;
if c[m]=0 then dec(m);
write(c[m]);
for i:=m-1 downto 1 do
begin
if (c[i]>=1000)and(c[i]=100)and(c[i]=10)and(c[i]=0)and(c[i] -
02009-07-09 16:21:39@
普通乘法,只是要用ansistring!水题!
-
02009-04-07 17:14:31@
program chengfa;
var str1,str2:string;
n1,n2,i,j,n,w,p,q:integer;
a,b:array[1..256] of integer;
c:array[1..1000] of integer;begin
readln(str1);readln(str2);
n1:=length(str1);
n2:=length(str2);
for i:=n1 downto 1 do val(str1[i],a[n1-i+1]);
for i:=n2 downto 1 do val(str2[i],b[n2-i+1]);
for i:=1 to (n1+n2) do c[i]:=0;
for i:=1 to n2 do
for j:=1 to n1 do
begin
w:=i+j-1;q:=c[w];
c[w]:=(q+(a[j]*b[i]) mod 10) mod 10;
c[w+1]:=c[w+1]+(q+(a[j]*b[i]) mod 10) div 10+ (a[j]*b[i]) div 10;
end;
for i:=(n1+n2) downto 1 do
if (c[i]0) then
begin
n:=i;break;
end;for i:=n downto 1 do write(c[i]);
end.
-
02009-04-06 10:41:15@
var
s1,s2,s3:ansistring;
a,b,c,d:array[0..5000]of longint;
i,j,k,l1,l2,la,lb,ka,kb,temp:longint;
begin
readln(s1);
readln(s2);
if length(s1)=0)and(c[j]=10)and(c[j]=100)and(c[j] -
02009-04-03 20:47:15@
TMD ~~~~~~~~`
竟然会 超时~~~~~~~\
怎么可能??????? -
02009-04-02 11:28:24@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 462ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:462msprogram p1040;
var
a,b,c:array[1..20001] of longint;
i,j,k,t,p,q:longint;
ch:char;
begin
p:=0;
while not eoln do begin
read(ch);
inc(p);
a[p]:=ord(ch)-48;
end;
readln;
q:=0;
while not eoln do begin
read(ch);
inc(q);
b[q]:=ord(ch)-48;
end;
for i:=1 to p div 2 do begin
k:=a[i];
a[i]:=a[p+1-i];
a[p+1-i]:=k;
end;
for i:=1 to q div 2 do begin
k:=b[i];
b[i]:=b[q+1-i];
b[q+1-i]:=k;
end;
fillchar(c,sizeof(c),0);
for i:=1 to p do
for j:=1 to q do
c:=c+a[i]*b[j];
for i:=1 to p+q do begin
c:=c+c[i] div 10;
c[i]:=c[i] mod 10;
end;
k:=20001;
while c[k]=0 do dec(k);
for i:=k downto 1 do
write(c[i]);
end. -
02009-03-28 12:48:40@
第一次写压位高精度。感觉不错
0MS
-
02009-03-22 08:44:39@
普通一位高精可以!
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 541ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:541ms -
02009-03-21 20:11:31@
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
---|---|---|---|---|---|---|---|-
Accepted 有效得分:100 有效耗时:0ms第一次写压位高精,居然卡了我一下午。。。= =
居然错在读入上了。。囧。。。
-
02009-03-19 18:21:39@
var i,j,k,l1,l2,m,g,n,c,x,z:longint;
a,b,y,jia:array[1..1000] of longint;
s1,s2:ansistring;
begin
readln(s1); l1:=length(s1); n:=500;
readln(s2); l2:=length(s2); z:=0;
for i:=l1 downto 1 do val(s1[i],a[n+i-l1],z);
for i:=l2 downto 1 do val(s2[i],b[n+i-l2],z);
for i:=n downto n-l2+1 do
begin
g:=0;
for j:=500 downto 1 do
begin
c:=a[j]*b[i]+g;
y[j]:=c mod 10;
g:=c div 10;
end;
g:=0;
for j:=500 downto 1 do
begin
c:=y[j]+jia[j]+g;
jia[j]:=c mod 10;
g:=c div 10;
end;
fillchar(y,sizeof(y),0);
z:=z+1;
end;
m:=1;
while jia[m]=0 do inc(m);
for i:=m to 500 do write(jia[i]);
end.
哪个地方错了~~5555 -
02009-03-18 15:59:18@
要压位.
-
02009-03-17 21:25:08@
交了5次才AC 太不容易了,开始数组里存一位数,最后一个数据超时,后来改成4位数…………………………
program p1040;
var a,b:array[-5..10000] of longint;
c:array[-5..100000000] of longint;
ch:ansistring;
l1,l2,m,k:longint;
procedure goin;
var l,min,i,j:longint; s:string;
begin
readln(ch); s:='';min:=10000;
l1:=length(ch);
for i:=l1 downto 1 do
begin
if length(s)=100 then write('0',c[m]) else
if c[m]>=10 then write('00',c[m]) else
if c[m]>=1 then write('000',c[m]) else
write('0000');
end;
writeln;
end.