AcWing 1209. 带分数
原题链接
简单
作者:
Bug-Free
,
2020-01-22 05:35:34
,
所有人可见
,
阅读 827
#include <algorithm>
#include <iostream>
using namespace std;
int n;
int num[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int a, b, c;
int ans;
int getNum(int l, int r)
{
int res = 0;
for(int i = l; i <= r; i++) res = res * 10 + num[i];
return res;
}
bool check(int a, int b, int c)
{
if(b % c != 0 || a + b / c != n) return false;
return true;
}
int main(void)
{
scanf("%d", &n);
do
{
for(int i = 0; i < 6; i++)
{
for(int j = i + 1; j < 8; j++)
{
a = getNum(0, i);
b = getNum(i + 1, j);
c = getNum(j + 1, 8);
if(check(a, b, c)) ans++;
}
}
} while(next_permutation(num, num + 9));
printf("%d\n", ans);
return 0;
}