AcWing 1209. 带分数
原题链接
简单
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 1e6 + 5;
int n, res;
int num[9] = {1,2,3,4,5,6,7,8,9};
int cal(int lef, int rig){
int x = lef;
int z = num[x];
int len = rig - lef;
while(len--){
z = z * 10 + num[++x];
}
return z;
}
int main(){
cin >> n;
do{
//cout << cal(0,8) << endl;
for(int i = 0; i <= 5; i++){
for(int j = i + 1; j < 8; j++){
int a = cal(0, i);
int b = cal(i + 1, j);
int c = cal(j + 1, 8);
if(a + b / c == n && b % c == 0) res++;
}
}
}while(next_permutation(num, num + 9));
cout << res << endl;
return 0;
}