USACO 1.3 牛式
2016-04-08 21:43
393 查看
Description下面是一个乘法竖式,如果用我们给定的那几个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式。 * * * x * * ------- * * * * * * ------- * * * *数字只能取代*,当然第一位不能为0。写一个程序找出所有的牛式。InputLine 1:
数字的个数。Line 2: N个用空格分开的数字(每个数字都∈{1,2,3,4,5,6,7,8,9})
。Output共一行,一个数字。表示牛式的总数。下面是样例的那个牛式。 2 2 2 x 2 2 ------ 4 4 4 4 4 4 --------- 4 8 8 4Sample Input
数字的个数。Line 2: N个用空格分开的数字(每个数字都∈{1,2,3,4,5,6,7,8,9})
。Output共一行,一个数字。表示牛式的总数。下面是样例的那个牛式。 2 2 2 x 2 2 ------ 4 4 4 4 4 4 --------- 4 8 8 4Sample Input
5
2 3 4 6 8Sample Output
1
解题思路:读入n,用五重循环,穷举乘数与乘数五个位置,也就是1到n,判断每一个是否符合题目要求,如果符合,就把num+1,最后输出num即可。
程序:
var
n,i,i1,i2,temp,i4,i3,m1,m2,num:longint;
a:array[1..10]of longint;
function p1(v:longint):boolean;
var
x,i,t,j:longint;
q:boolean;
begin
x:=v;i:=0;
while x<>0 do
begin
t:=x mod 10;
j:=0;q:=false;
while j<=n do
begin
inc(j);
if t=a[j] then begin q:=true; break; end;
end;
if (q=false)or(t=0) then exit(false);
x:=x div 10;
inc(i);
end;
if (i=3)and(v<>0) then p1:=true else p1:=false;
end;
function p2(v:longint):boolean;
var
x,i,t,j:longint;
q:boolean;
begin
x:=v;i:=0;
while x<>0 do
begin
t:=x mod 10;
j:=0;q:=false;
while j<=n do
begin
inc(j);
if t=a[j] then begin q:=true;break; end;
end;
if (q=false)or(t=0) then exit(false);
x:=x div 10;
inc(i);
end;
if (i=4)and(v<>0) then p2:=true else p2:=false;
end;
begin
readln(n);
for i:=1 to n do read(a[i]);
num:=0;
for i:=1 to n do
if a[i]<>0 then
for i1:=1 to n do
for i2:=1 to n do
for i3:=1 to n do
if a[i3]<>0 then
for i4:=1 to n do
begin
m1:=a[i]*100+a[i1]*10+a[i2];
m2:=a[i3]*10+a[i4];
if (p1(m1*a[i4]))and(p1(m1*a[i3]))and(p2(m1*m2)) then inc(num);
end;
writeln(num);
end.
相关文章推荐
- USACO&nbsp;1.2&nbsp;双重回文数
- USACO&nbsp;1.2&nbsp;回文平方数
- USACO&nbsp;1.2&nbsp;方块转换
- USACO&nbsp;1.2&nbsp;挤牛奶
- USACO&nbsp;1.1&nbsp;你要乘坐的飞碟在这里
- USACO&nbsp;1.1&nbsp;黑色星期五
- USACO&nbsp;1.1&nbsp;贪婪的礼物送礼者
- USACO&nbsp;1.1&nbsp;破碎的项链
- 求二叉树的后序遍历(树)
- 查找单词树(树)
- 约瑟夫问题(指针变量及线性链表)
- Android 开发知识点
- c#输入
- js 将json字符串转为js对象
- Android适配器之ArrayAdapter、SimpleAdapter和BaseAdapter的简单用法
- 【脚本化文档】——属性&元素的内容
- ACM程序设计选修课——1076汇编语言(重定向+模拟)
- 麻将游戏(广度优先搜索)
- 删数问题(指针变量与线性链表)
- 建先进先出的链表(指针变量及线性…