AcWing 1209. 带分数
原题链接
简单
作者:
uchar
,
2024-12-05 22:58:39
,
所有人可见
,
阅读 10
暴力求解 0.2s
#include <iostream>
#include <algorithm>
using namespace std;
int vec[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int cal(int x, int y)
{
int t = 0;
for (int i = x; i <= y; i ++ )
t = t * 10 + vec[i];
return t;
}
int main()
{
int target, a, b, c, t, cnt = 0, ans = 0;
cin >> t;
target = t;
while (t) // 求a的最大数位
{
cnt ++;
t /= 10;
}
do
{
for (int i = 0; i <= cnt - 1; i ++ )
{
for (int j = i + 1; j <= 7; j ++ )
{
a = cal(0, i);
b = cal(i + 1, j);
c = cal(j + 1, 8);
if (target * c == a * c + b ) ans ++;
}
}
} while (next_permutation(vec, vec + 9));
printf("%d", ans);
return 0;
}