LiChenyi05 @ 2024-03-29 23:16:39
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
int A,B,C;
cin>>A>>B>>C;
for(int a=1;a<=9;a++)
{
for(int b=1;b<=9&&b!=a;b++)
{
for(int c=1;c<=9&&c!=a&&c!=b;c++)
{
for(int d=1;d<=9&&d!=a&&d!=b&&d!=c;d++)
{
for(int e=1;e<=9&&e!=a&&e!=b&&e!=c&&e!=d;e++)
{
for(int f=1;f<=9&&f!=a&&f!=b&&f!=c&&f!=d&&f!=e;f++)
{
for(int g=1;g<=9&&g!=a&&g!=b&&g!=c&&g!=d&&g!=e&&g!=f;g++)
{
for(int h=1;h<=9&&h!=a&&h!=b&&h!=c&&h!=d&&h!=e&&h!=f&&h!=g;h++)
{
for(int i=1;i<=9&&i!=a&&i!=b&&i!=c&&i!=d&&i!=e&&i!=f&&i!=g&&i!=h;i++)
{
int ans1=(a*100+b*10+c)*B*C;
int ans2=(d*100+e*10+f)*A*C;
int ans3=(g*100+h*10+i)*A*B;
if(ans1==ans2&&ans1==ans3)
{
cout<<a<<b<<c<<" "<<d<<e<<f<<" "<<g<<h<<i<<endl;
}
}
}
}
}
}
}
}
}
}
return 0;
}
在编译器上连结果都不输出,这是为啥啊
by Sizeof_cpp @ 2024-03-29 23:52:04
1. ###### - 必须超时了****
by Tomle @ 2024-03-30 07:22:45
@gjh2023 时间复杂度实际上是
by Tomle @ 2024-03-30 07:27:11
破案了,for 循环写法
例如第二层 for 循环,应该写为:
for(int b=1;b<=9;b++)
{
if(a==b)continue;
...
}
你的代码会导致变量 b = a 时就跳出循环
by LiChenyi05 @ 2024-03-30 14:38:47
@Tomle 谢谢您
by Tomle @ 2024-03-30 16:55:42
@LiChenyi05 关注下呗
by LiChenyi05 @ 2024-03-30 22:59:29
@Tomle okkkkkkk