讨论 / 产生数(PID=68) 大牛进 [悬赏3分]
woshiniba 2011-10-17 02:31:00
点我顶贴 收藏 删除
附40分的源代码:

program project1;

var

rule:array [0..9] of longint;

a:array [1..100] of longint;

s,s2:string;

i,j,k,len:longint;

from,too:longint;

begin

readln(s);

k:=pos(’ ’,s);

s2:=copy(s,k+1,length(s)-k);

s:=copy(s,1,k-1);

val(s2,k);

for i:=0 to 9 do rule[i]:=1;

for i:=1 to k do

begin

readln(from,too);

inc(rule[from]);

end;

a[1]:=1; len:=1;

for i:=1 to length(s) do

begin

k:=ord(s[i])-48;

for j:=1 to len do

begin

a[j]:=a[j]*rule[k];

a[j]:=a[j]+a[j-1] div 10;

a[j-1]:=a[j-1] mod 10;

end;

while a[len]>=10 do

begin

inc(len);

a[len]:=a[len-1] div 10;

a[len-1]:=a[len-1] mod 10;

end;

end;

for i:=len downto 1 do

write(a[i]);

readln; readln;

end.

#1 lychees@2008-10-23 04:26:00
回复 删除
for k:=0 to 9 do

for i:=0 to 9 do

for j:=0 to 9 do

if i<>j then G[i,j]:=G[i,j] or G[i,k] and G[k,j];

沃舍尔算法可以帮助我们求出所有的传递闭包~

#2 Zx.MYS@2008-10-23 04:33:00
回复 删除
好高深……
#3 Zx.MYS@2008-10-23 04:36:00
回复 删除
忽然看懂了,原来沃舍尔=Warshall

- -……

#4 woshiniba@2008-10-26 02:05:00
回复 删除
根据各位大牛的意见,我把程序改了。但还是60分……

状态: [color=red]Unaccepted [/color]

测评机: Xeond[6]

得分: 60分

提交日期: 2008-10-24 13:11:00

有效耗时: 438毫秒

测试结果1: [color=green]通过本测试点|有效耗时171:ms[/color]

测试结果2: [color=green]通过本测试点|有效耗时47:ms[/color]

测试结果3: [color=green]通过本测试点|有效耗时63:ms[/color]

测试结果4: [color=red]输出过少|用户输出数据少于标准输出的50%[标准输出14位|选手输出6位][/color]

测试结果5: 测试结果错误.错误结果为:19672689770496

正确结果应为:3427648537559040000000

测试结果6: [color=green]通过本测试点|有效耗时47:ms[/color]

测试结果7: [color=green]通过本测试点|有效耗时47:ms[/color]

测试结果8: [color=green]通过本测试点|有效耗时63:ms[/color]

测试结果9: [color=red]输出过少|用户输出数据少于标准输出的50%[标准输出14位|选手输出6位][/color]

测试结果10: 测试结果错误.错误结果为:19672689770496

正确结果应为:3427648537559040000000

提交代码: program project1;

var

b:array [0..9,0..9] of longint;

rule:array [0..9] of longint;

a:array [1..100] of longint;

s,s2:string;

i,j,m,k,len:longint;

from,too:longint;

function max(a,b:longint):longint;

begin

if a>b then exit(a)

else exit(b);

end;

begin

readln(s);

k:=pos(’ ’,s);

s2:=copy(s,k+1,length(s)-k);

s:=copy(s,1,k-1);

val(s2,k);

fillchar(b,sizeof(b),0);

for i:=0 to 9 do rule[i]:=1;

for i:=1 to k do

begin

readln(from,too);

b[from,too]:=1;

end;

for m:=0 to 9 do

for i:=0 to 9 do

for j:=0 to 9 do

if (i<>j) and (b[i,j]=0) and (b[i,k]>0) and (b[k,j]>0)

then b[i,j]:=1;

for i:=0 to 9 do

begin

for j:=0 to 9 do

if b[i,j]>0 then inc(rule[i]);

end;

a[1]:=1; len:=1;

for i:=1 to length(s) do

begin

k:=ord(s[i])-48;

for j:=1 to len do

begin

a[j]:=a[j]*rule[k];

a[j]:=a[j]+a[j-1] div 10;

a[j-1]:=a[j-1] mod 10;

end;

while a[len]>=10 do

begin

inc(len);

a[len]:=a[len-1] div 10;

a[len-1]:=a[len-1] mod 10;

end;

end;

for i:=len downto 1 do

write(a[i]);

readln; readln;

end.

#5 Zx.MYS@2008-10-26 02:07:00
回复 删除
int64/qword
#6 woshiniba@2008-10-26 21:55:00
回复 删除
这是用高精度做的了 没必要改~~ 因为我试过了……
#7 LIFE@2008-10-27 01:39:00
回复 删除
用到传递闭包,所以用FLOYD处理一下就行,然后再用乘法原理计算就可完美AC
#8 woshiniba@2008-10-28 22:00:00
回复 删除
我已经用floyd改过了,60分~~ 总比40分好……

附最新源代码,各位大牛注意了:

program project1;

var

b:array [0..9,0..9] of int64;

rule:array [0..9] of int64;

a:array [1..100] of int64;

s,s2:string;

i,j,m,k,len:longint;

from,too:longint;

function max(a,b:int64):int64;

begin

if a>b then exit(a)

else exit(b);

end;

begin

readln(s);

k:=pos(’ ’,s);

s2:=copy(s,k+1,length(s)-k);

s:=copy(s,1,k-1);

val(s2,k);

fillchar(b,sizeof(b),0);

for i:=0 to 9 do rule[i]:=1;

for i:=1 to k do

begin

readln(from,too);

b[from,too]:=1;

end;

for m:=0 to 9 do

for i:=0 to 9 do

for j:=0 to 9 do

if (i<>j) and (b[i,j]=0) and (b[i,k]>0) and (b[k,j]>0)

then b[i,j]:=1;

for i:=0 to 9 do

begin

for j:=0 to 9 do

if b[i,j]>0 then inc(rule[i]);

end;

a[1]:=1; len:=1;

for i:=1 to length(s) do

begin

k:=ord(s[i])-48;

for j:=1 to len do

begin

a[j]:=a[j]*rule[k];

a[j]:=a[j]+a[j-1] div 10;

a[j-1]:=a[j-1] mod 10;

end;

while a[len]>=10 do

begin

inc(len);

a[len]:=a[len-1] div 10;

a[len-1]:=a[len-1] mod 10;

end;

end;

for i:=len downto 1 do

write(a[i]);

readln; readln;

end.

#9 woshiniba@2008-11-08 05:24:00
回复 删除
我知道为什么错了…… floyd段我写的是m 应该是k……
#10 583158450@2011-10-16 22:25:00
回复 删除
!!!!

计算答案时 可定义 ans:real; 然后做乘法运算 最后write(ans:0:0);即可

不必用高精度

查看更多回复
提交回复