文档库 最新最全的文档下载
当前位置:文档库 › A9数字

A9数字

A9数字
A9数字

Problem A:【(GDOI 2009)东莞市选拔赛】9数字

Time Limit:1000MS Memory Limit:65536K

Total Submit:77 Accepted:16

Description

有一天,Merlin同学突然发现一件有趣的事情。1到100之间的整数,有一些写成带分数的形式后,刚好使用了1到9这9个数字各一次,例如对于6,可以写成:

现在给定一个1到100之间的整数,请你找出所有满足这种形式的方案,即

其中,A是给定的整数,B、C和D是正整数,并且在B、C、D三个数中,1到9这9个数字恰好都出现过一次且仅一次。

Input

输入仅一个正整数A(A <= 100)。

Output

输出满足要求的所有方案。其中,先输出B最小的方案,B相同的情况下先输出C最小的方案。题目保证对于输入的A起码存在一个方案。

注意,在输出样例中的字母x只是用于占位,让选手可以清楚输出的格式,实际输出中请用空格代替x!

Sample Input

45

Sample Output

xxxxx3564

45=27----

xxxxxx198

xxxxx4172

45=38----

xxxxxx596

程序:

?var a,b,c,d:longint;

? s:string;

? total,e:set of '0'..'9';

?function merge(x:longint):boolean;

?var i:integer;

? s:string;

?begin

? merge:=true;

? str(x,s);

? for i:=1 to length(s) do

? if s[i] in total then total:=total-[s[i]]

? else exit;

? exit(false);

?end;

?procedure print;

?var i:integer;

? s1,s2,s3:string;

?begin

? str(c,s1);

? str(a,s2); s2:=s2+'=';

? str(b,s3); s2:=s2+s3;

? str(d,s3);

? for i:=1 to length(s1) do s2:=s2+'-';

? for i:=1 to length(s2)-length(s1) do s1:=' '+s1;

? for i:=1 to length(s2)-length(s3) do s3:=' '+s3;

? writeln(s1);

? writeln(s2);

? writeln(s3);

?end;

?Begin

? readln(a);

? e:=['1'..'9'];

? for b:=1 to a-1 do begin

? for d:=1 to 9876 do begin

? c:=d*(a-b);

? if c>100000 then break;

? total:=e;

? if merge(b) then continue; ? if merge(d) then continue; ? if merge(c) then continue; ? if total=[] then print;

? end;

? end;

?End.

?

相关文档