代码:
#include <ctime>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
int n,w[1000],ans=0,pow(int i);
int pow(int i)
{
int s=1;
for(int j=0;j<i;j++)s*=10;
return s;
}
bool check2(int a,int b)
{
int s=0;//用于计数
for(int i=0;i<b;i++)
{
for(int j=0;j<n;j++)
{
if(a/pow(i)%10==w[j])s++;
}
}
if(s<b) return true;
else return false;
}
bool check1(int a,int b)
{
int m=b%10,n=b/10%10;
int x=m*a,y=n*a;
int z=x+y*10;
if(x/1000!=0||y/1000!=0||z/10000!=0) return false;
//虽然下面有判断语句了,但是可能存在四位数满足三位数的情况
if(check2(x,3)||check2(y,3)||check2(z,4)) return false;
return true;
}
int main() {
scanf("%d",&n);
for(int i=0; i<n; i++) scanf("%d",&w[i]);
for(int i=100;i<=999;i++)
{
if(check2(i,3)) continue;
for(int j=10;j<=99;j++)
{
if(check2(j,2)) continue;
if( check1(i,j)) ans++;
}
}
cout<<ans;
return 0;
}
1.check2用于判断给定限定的数字能否组成要求的数字,值得细品。
2.check1集成了之后的所有操作,其中值得注意容易疏忽的就是除了判断是否由对应数字组成,还得判断是否是对应的数位(也就是得排除是四位数但也能通过check2的情况)