AcWing 1209. 带分数
原题链接
简单
作者:
RwChen
,
2021-06-23 00:01:04
,
所有人可见
,
阅读 217
平均2.5s感觉比赛会TLE
C++ 代码
#include <iostream>
#include <algorithm>
using namespace std;
int nums[] = {1,2,3,4,5,6,7,8,9};
int to_num(int start, int end)
{
int res = 0;
for(int i = start; i < end; i++)
res = res * 10 + nums[i];
return res;
}
int main()
{
int n, ans = 0;
cin >> n;
do
{
bool f = true;
for(int i = 1; i <= 7 && f; i++)
{
for(int j = 1; j <= 8 - i; j++)
{
int a = to_num(0, i);
int b = to_num(i, i + j);
int c = to_num(i + j, 9);
if(a >= n)
{
f = false;
break;
}
if(b % c == 0)
{
if(a + b / c == n)
ans++;
}
}
}
}
while(next_permutation(nums, nums + 9));
cout << ans << endl;
return 0;
}