usaco1.3 crypt1 2008.11.5
{Tips:
1.用到了哈希判重
2.这是一道简单的题,只要耐心就行了。}
{
ID:
PROG: crypt1
LANG: PASCAL
}
program kakashi;
const
oo:array[1..9]of char=('1','2','3','4','5','6','7','8','9');
var
num:array[1..9,1..9,1..9,1..9]of -1..1;
x,i,j,k,m,n,p,tot:longint;
a:array[1..9]of 1..9;
b:set of '0'..'9';
f1,f2:text;
function deal(uu,la,lb:longint):boolean;
var
ux:string;
lx,s:longint;
begin
if (uu>la)and(uu<lb) then
begin
str(uu,ux);
lx:=length(ux);
deal:=true;
for s:=1 to lx do
if not(ux[s]in b) then deal:=false;
end
else deal:=false;
end;
procedure find(y:longint);
begin
if deal(x*a[y],99,1000) then num[i,j,k,y]:=1 else num[i,j,k,y]:=-1;
end;
begin
assign(f1,'crypt1.in');
reset(f1);
assign(f2,'crypt1.out');
rewrite(f2);
readln(f1,p);
fillchar(num,sizeof(num),0);
tot:=0;
for i:=1 to p do
read(f1,a[i]);
for i:=1 to p do
b:=b+[oo[a[i]]];
for i:=1 to p do
for j:=1 to p do
for k:=1 to p do
begin
x:=100*a[i]+10*a[j]+a[k];
for m:=1 to p do
if (num[i,j,k,m]<>-1) then
begin
if (num[i,j,k,m]=0) then
find(m);
if num[i,j,k,m]=1 then
for n:=1 to p do
if (num[i,j,k,n]<>-1) then
{=3=}begin
if num[i,j,k,n]=0 then
find(n);
if num[i,j,k,n]=1 then
if (deal(x*(10*a[m]+a[n]),999,10000)) then
inc(tot);
{=3=}end;
{=1=} end;
end;
writeln(f2,tot);
close(f1);
close(f2);
end.
data
TASK: crypt1
LANG: PASCAL
Compiling...
Compile: OK
Executing...
Test 1: TEST OK [0 secs]
Test 2: TEST OK [0.004 secs]
Test 3: TEST OK [0.004 secs]
Test 4: TEST OK [0 secs]
Test 5: TEST OK [0.004 secs]
Test 6: TEST OK [0.004 secs]
Test 7: TEST OK [0.004 secs]
All tests OK.
YOUR PROGRAM ('crypt1') WORKED FIRST TIME! That's fantastic
-- and a rare thing. Please accept these special automated
congratulations.
Here are the test data inputs:
------- test 1 -------
5
2 3 4 6 8
------- test 2 -------
4
2 3 5 7
------- test 3 -------
1
1
------- test 4 -------
7
4 1 2 5 6 7 3
------- test 5 -------
8
9 1 7 3 5 4 6 8
------- test 6 -------
6
1 2 3 5 7 9
------- test 7 -------
9
1 2 3 4 5 6 7 8 9
----------------------
Keep up the good work!
Thanks for your submission!