洛谷P1618 三连击(升级版)
作者:
hayate
,
2024-02-12 11:43:11
,
所有人可见
,
阅读 60
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 20;
int a,b,c;
bool st[N];
int nums[N];
bool flag = false;
void check()
{
int x = nums[0] * 100 + nums[1] * 10 + nums[2];
int y = nums[3] * 100 + nums[4] * 10 + nums[5];
int z = nums[6] * 100 + nums[7] * 10 + nums[8];
if (x * b == y * a && x * c == z * a)
{
flag = true;
cout << x << " " << y << " " << z << endl;
}
}
void dfs(int u)
{
if (u == 9)
{
check();
return;
}
for(int i=1;i<=9;i++)
{
if(!st[i])
{
st[i]=true;
nums[u]=i;
dfs(u+1);
st[i]=false;
}
}
}
int main()
{
cin>>a>>b>>c;
dfs(0);
if(!flag)
{
cout<<"No!!!"<<endl;
}
return 0;
}