Prime Cryptarithm

http://train.usaco.org/usacoprob2?a=dofOQ4vbPD7&S=crypt1

题不难,题意很重!很重要!

题目大意:

      * * *
   x    * *
    -------
      * * *         <-- partial product 1
    * * *           <-- partial product 2
    -------
    * * * *
把给定的数字带入上面乘法竖式后能使竖式成立的式子称为“ 牛式

输入一组数字,找出所有的牛式

注意:

partial product 1,partial product 2 都是三位数
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>
using namespace std;
bool f[10];		//可用的数字 
int a[10];
bool isok(int temp)
{
	while(temp)
	{
		if(!f[temp%10]) return false;
		temp /= 10;
	}
	return true;
}
int main()
{
	ifstream fin("crypt1.in");
	ofstream fout("crypt1.out");
	int n, temp, k, c1, c2, ans;
	while(fin >> n)
	{
		memset(f, 0, sizeof(f));
		ans = k = 0;
		for(int i = 0; i < n; i++) 
		{
			fin >> temp;
			if(!f[temp])
			{
				f[temp] = true;
				a[k++] = temp;
			}
		}
		for(int i = 0; i < k; i++)
		{
			for(int j = 0; j < k; j++)
			{
				for(int m = 0; m < k; m++)
				{
					c1 = a[i]*100 + a[j]*10 + a[m];
					for(int x = 0; x < k; x++)
					{
						if(a[x]*c1 >= 1000) continue;
						for(int y = 0; y < k; y++)
						{
							if(a[y]*c1 >= 1000) continue;
							c2 = a[x]*10 + a[y];
							if(isok(c1*a[x]) && isok(c1*a[y]) && isok(c1*c2))
								ans++;	
						}
					}
				}
			}
		}
		fout << ans << endl;
	}
	fout.close();
	return 0;
}


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值