AcWing 1209. 带分数
原题链接
简单
作者:
愛_
,
2024-11-30 13:28:43
,
所有人可见
,
阅读 1
#include <iostream>
using namespace std;
const int N = 100010;
int n;
int num[N];
bool d[N];
int selcet(int l,int r) //分段的函数
{
int res = 0;
for (int i = l; i <=r; i++)
{
res = res*10 + num[i];
}
return res;
}
int cnt;
void dfs(int u)
{
if (u == 9)
{
for (int i = 0; i < 7; i++) //i<7保证后边b,c有数字可选
{
for (int j = i+1; j < 8; j++) //将a[N]分成三段
{
int a = selcet(0,i);
int b = selcet(i+1,j);
int c = selcet(j+1,8);
if (a*c + b == c*n)cnt++; //c++为整除,换成乘法,防止小数点没算到
}
}
}
for (int i = 1; i <= 9; i++)
{
if (!d[i])
{
num[u] = i;
d[i] = true;
dfs(u + 1);
d[i] = false;
}
}
}
int main()
{
cin >> n;
dfs(0);
cout << cnt << endl;
return 0;
}