168 条题解
-
-1
zsy78191 LV 7 @ 2012-11-29 12:23:45
VijosNT Mini 2.0.5.7 Special for Vijos
编译通过...
├ 测试数据 01:答案正确... (0ms, 248KB)
├ 测试数据 02:答案正确... (0ms, 248KB)
├ 测试数据 03:答案正确... (15ms, 248KB)
├ 测试数据 04:答案正确... (74ms, 248KB)
├ 测试数据 05:答案错误... (31ms, 248KB)
├ 测试数据 06:答案正确... (0ms, 248KB)
├ 测试数据 07:答案正确... (46ms, 248KB)
├ 测试数据 08:答案正确... (0ms, 248KB)
├ 测试数据 09:答案错误... (15ms, 248KB)
├ 测试数据 10:答案正确... (0ms, 248KB)谁能把第五个数据和第九个数据透露一下。。蛋疼。
-
-1@ 2012-11-06 17:07:39
高精度,具体方法还是数组解决...程序不简单
-
-1@ 2012-09-16 11:27:38
var a,b,c:integer;
begin
read(a,b);
if a>b then c:=a else c:=b;
while (c mod a0) or (c mod b0) do c:=c+1;
write(C)
end. -
-1@ 2010-04-02 15:09:08
#include
using namespace std;
int main(){
long long i,j,c,max,min;
while(cin>>i>>j){
if(i -
-1@ 2010-03-08 20:31:48
87行 1次AC 很爽感
不过调了很久
GCD对于高精还是不用函数用过程好,否则爆栈。。 -
-1@ 2009-11-09 15:48:21
type
nt=array[1..2,1..101]of longint;var
t,s:string;
a,b:nt;
i,j,l1,l2:longint;
flag:boolean;procedure adda(var a:nt);
var
i:longint;
begin
for i:=l1 downto 1 do
begin
a[2,i]:=a[2,i]+a[1,i];
a[2,i+1]:=a[2,i+1]+a[2,i] div 10;
a[2,i]:=a[2,i] mod 10;
end;
if a[2,l1+1]>0 then inc(l1);
end;procedure addb(var b:nt);
var
i:longint;
begin
for i:=l2 downto 1 do
begin
b[2,i]:=b[2,i]+b[1,i];
b[2,i+1]:=b[2,i+1]+b[2,i] div 10;
b[2,i]:=b[2,i] mod 10;
end;
if b[2,l2+1]>0 then inc(l2);
end;procedure print;
begin
for i:=l1 downto 1 do
write(a[2,i]);
writeln;
flag:=false;
end;procedure getmin(var a,b:nt);
begin
if l1l2 then addb(b)
else
begin
for i:=l1 downto 1 do
if a[2,i]=b[2,i] then continue
else
if a[2,i]b[2][i] then
begin
addb(b);
exit;
end;
print;
end;
end;begin
flag:=true;
readln(s);t:=copy(s,1,pos(' ',s)-1);
l1:=length(t);
for i:=1 to l1 do
val(t[i],a[2,l1-i+1]);
a[1]:=a[2];t:=copy(s,pos(' ',s)+1,length(s)-l1-1);
l2:=length(t);
for i:=1 to l2 do
val(t[i],b[2,l2-i+1]);
b[1]:=b[2];while flag do getmin(a,b);
end.
先膜拜下matrix67神牛。OTL。
好,开始。
他blog里面有篇求lcm的文章,觉得那方法很叼。于是就来做这题,
参看 http://www.matrix67.com/blog/archives/554
结果基本上都超时了。。
我的程序,用a[1],b[1]来记录初始值,a[2]参与运算。
就用的matrix67的思想(我说过一次了)。
但是TLE了6个点。(我又说过了)。
各位看下有什么优化的方法。
-
-1@ 2009-11-09 10:19:14
const base=10;
type arr=array[0..210] of longint;
var a,b,d,g,w:arr;procedure getin;
var i,j:longint; str:string;
begin
readln(str);
j:=pos(' ',str);
i:=j-1;
fillchar(a,sizeof(a),0);
while i>0 do
begin
a[0]:=a[0]+1;
if i>1 then
begin val(copy(str,i,1),a[a[0]]); i:=i-1 end
else
begin val(copy(str,1,i),a[a[0]]); break end;
end;
str:=copy(str,j+1,length(str)-j);
i:=length(str);
fillchar(b,sizeof(b),0);
while i>0 do
begin
b[0]:=b[0]+1;
if i>1 then
begin val(copy(str,i,1),b[b[0]]); i:=i-1 end
else
begin val(copy(str,1,i),b[b[0]]); break end;
end;
end;function equal(a,b:arr):boolean;
var i:longint;
begin
if a[0]b[0] then exit(false);
for i:=1 to a[0] do
if a[i]b[i] then exit(false);
equal:=true;
end;function bigger(a,b:arr):boolean;
var i:longint;
begin
if a[0]>b[0] then exit(true);
if a[0]0 then a[0]:=a[0]+1;
end;procedure minus(var a,b:arr;dl:longint);
var c:arr; i:longint;
begin
fillchar(c,sizeof(c),0);
c[0]:=b[0]+dl;
for i:=1 to b[0] do c:=b[i];
for i:=1 to a[0] do
begin
a[i]:=a[i]-c[i];
if a[i]0) and (a[a[0]]=0) do a[0]:=a[0]-1;
end;procedure plus(var a:arr;dl:longint);
var i:longint;
begin
a[dl+1]:=a[dl+1]+1;
i:=dl+1;
while a[i]>=base do
begin
a:=a+a[i] div base;
a[i]:=a[i] mod base;
i:=i+1;
end;
if i>a[0] then a[0]:=i;
end;procedure mul(a,b:arr;var w:arr);
var i,j:longint; c:arr;
begin
fillchar(c,sizeof(c),0);
for i:=1 to a[0] do
for j:=1 to b[0] do
begin
c:=c+a[i]*b[j];
if c>=base then
begin
c:=c+c div base;
c:=c mod base;
end;
end;
i:=1;
while i=base then
begin
c:=c+c[i] mod base;
c[i]:=c[i] div base;
end;
i:=i+1;
end;
i:=201;
while c[i]=0 do i:=i-1;
c[0]:=i;
w:=c;
end;procedure gcd(a,b:arr);
var i:longint;
begin
fillchar(g,sizeof(g),0);
g[0]:=1; g[1]:=1;
while not equal(a,b) do
begin
if not odd(a[1]) then
if not odd(b[1]) then
begin div2(a); div2(b); mul2(g) end
else div2(a)
else
if not odd(b[1]) then div2(b)
else if bigger(a,b) then minus(a,b,0) else minus(b,a,0);
end;
mul(g,a,g);
end;function larger(a,b:arr;dl:longint):boolean;
var c:arr; i:longint;
begin
fillchar(c,sizeof(c),0);
c[0]:=b[0]+dl;
for i:=1 to b[0] do c:=b[i];
larger:=bigger(a,c);
end;procedure divi(var a,b,c:arr);
begin
fillchar(c,sizeof(c),0);
while a[0]>0 do
if a[0]>b[0] then
if larger(a,b,a[0]-b[0]) then
begin
plus(c,a[0]-b[0]);
minus(a,b,a[0]-b[0]);
end
else begin
plus(c,a[0]-b[0]-1);
minus(a,b,a[0]-b[0]-1);
end
else begin
plus(c,a[0]-b[0]);
minus(a,b,a[0]-b[0]);
end;
end;procedure out(a:arr);
var i:longint;
begin
for i:=a[0] downto 1 do write(a[i]); writeln;
end;begin
getin;
gcd(a,b);
mul(a,b,w);
if (g[0]=1) and (g[1]=1) then out(w)
else begin
divi(w,g,d);
out(d);
end;
end.没有做高除 用的是在末尾添零的方法
-
-1@ 2009-08-11 21:18:47
program f;
var a,b:integer;
function apple(a1,b1:integer):integer;
var i:integer;
begin
for i:=1 to a1 do
if (i*b1mod a1=0)then
begin apple:=i*b1;break;end;
end;
begin
readln(a,b);
writeln(apple(a,b));
readln;
end.