5 条题解
-
1
正正正正正解
#include<bits/stdc++.h> #define int long long #define PII pair<int,int> #define ULL unsigned long long #define all(v) v.begin(), v.end() #define debug(a) cout<<#a<<"="<<a<<endl; using namespace std; constexpr int N = 1 * 1e6 + 10,M = 5 * 1e3 + 10,inf = 0x3f3f3f3f; int path[N],bin[N]; bool st[N]; set<PII> ans; void dfs2(int u,int sum) { if(sum > 9) return; if(u == 3) { if(sum == 9) { int num[3] = {0},l = 0 , r = bin[0]; for(int i=0;i<3;i++) { for(int j=l;j<r;j++) { num[i] += path[j]; num[i] *= 10; } num[i] /= 10; l += bin[i]; r += bin[i+1]; } // cout << num[0] << ' ' << num[1] << ' ' << num[2] << '\n'; sort(num,num+3,greater<int>()); if(num[0] == num[1]*num[2]) { // printf("%d = %d x %d\n",num[0],num[1],num[2]); ans.insert({num[0],num[1]}); } } return; } for(int i=1;i<=9;i++) { bin[u] = i; dfs2(u+1,sum+i); } } void dfs1(int u) { if(u==9) { dfs2(0,0); return; } for(int i=1;i<=9;i++) { if(st[i]) continue; st[i] = 1; path[u] = i; dfs1(u+1); st[i] = 0; } } void solve() { dfs1(0); vector<PII> res; res.assign(all(ans)); swap(res[1],res[2]); swap(res[3],res[4]); for(auto [a,b] : res) { printf("%d = %d x %d\n",a,a/b,b); } } signed main() { ios::sync_with_stdio(0);cin.tie(nullptr),cout.tie(nullptr); int _=1; // cin>>_; while(_--) { solve(); } return 0; } /** * author: Nijika_jia * created: 2024.12.08 17:58:10 */ ``` ```
-
1
#include <iostream> #include <algorithm> using namespace std; int x1, y1, x2, y2; int sum; int main() { int arr[9] = {1,2,3,4,5,6,7,8,9}; while(next_permutation(arr, arr+9)) { sum = 1000*arr[0] + 100*arr[1] + 10*arr[2] + arr[3]; x1 = arr[4]; y1 = 1000*arr[5] + 100*arr[6] + 10*arr[7] + arr[8];//第一种组合情况 x2 = 10*arr[4] + arr[5]; y2 = 100*arr[6] + 10*arr[7] + arr[8];//第二种组合情况 if(sum == x1*y1) { cout << sum << " = "<< x1 << " x " << y1 << endl; } else if(sum == x2*y2) { cout << sum << " = "<< x2 << " x " << y2 << endl; } } return 0; }
-
0
#include<iostream> using namespace std; int main() { cout<<"4396 = 28 x 157"<<"\n" <<"5346 = 18 x 297"<<"\n" <<"5346 = 27 x 198"<<"\n" <<"5796 = 12 x 483"<<"\n" <<"5796 = 42 x 138"<<"\n" <<"6952 = 4 x 1738"<<"\n" <<"7254 = 39 x 186"<<"\n" <<"7632 = 48 x 159"<<"\n" <<"7852 = 4 x 1963"<<endl; return 0; }
-
-1
参考答案:
#include<iostream> using namespace std; int main() { cout << "4396 = 28 x 157" << endl; cout << "5346 = 18 x 297" << endl; cout << "5346 = 27 x 198" << endl; cout << "5796 = 12 x 483" << endl; cout << "5796 = 42 x 138" << endl; cout << "6952 = 4 x 1738" << endl; cout << "7254 = 39 x 186" << endl; cout << "7632 = 48 x 159" << endl; cout << "7852 = 4 x 1963" << endl; return 0; }
- 1
信息
- ID
- 4
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- 递交数
- 16
- 已通过
- 7
- 上传者