6 条题解
-
4
题解
这道题就直接枚举 ,,然后判断,就是把这几个数放进数组排序,如果按顺序就对了。
#include <bits/stdc++.h> using namespace std; bool check(int a, int b, int c) { int p1 = a / 100 % 10, p2 = a / 10 % 10, p3 = a / 1 % 10; int p4 = b / 100 % 10, p5 = b / 10 % 10, p6 = b / 1 % 10; int p7 = c / 100 % 10, p8 = c / 10 % 10, p9 = c / 1 % 10; int k[10]; k[1] = p1; k[2] = p2; k[3] = p3; k[4] = p4; k[5] = p5; k[6] = p6; k[7] = p7; k[8] = p8; k[9] = p9; sort(k + 1, k + 10); // 排序 return k[1] == 1 && k[2] == 2 && k[3] == 3 && k[4] == 4 && k[5] == 5 && k[6] == 6 && k[7] == 7 && k[8] == 8 && k[9] == 9; // 判断 } int main() { for (int i = 1; i <= 999; i++) { if (check(i, i * 2, i * 3)) { printf("%d %d %d\n", i, i * 2, i * 3); // 输出 } } return 0; } // 其实没啥可写的,1998年的题看代码也能看懂
#include <bits/stdc++.h> using namespace std; bool check(int a, int b, int c) { int p1 = a / 100 % 10, p2 = a / 10 % 10, p3 = a / 1 % 10; int p4 = b / 100 % 10, p5 = b / 10 % 10, p6 = b / 1 % 10; int p7 = c / 100 % 10, p8 = c / 10 % 10, p9 = c / 1 % 10; int k[10]; k[1] = p1; k[2] = p2; k[3] = p3; k[4] = p4; k[5] = p5; k[6] = p6; k[7] = p7; k[8] = p8; k[9] = p9; sort(k + 1, k + 10); return k[1] == 1 && k[2] == 2 && k[3] == 3 && k[4] == 4 && k[5] == 5 && k[6] == 6 && k[7] == 7 && k[8] == 8 && k[9] == 9; } int main() { for (int i = 1; i <= 999; i++) { if (check(i, i * 2, i * 3)) { printf("%d %d %d\n", i, i * 2, i * 3); } } return 0; }
-
2
so easy
#include <bits/stdc++.h> using namespace std; bool check(int a, int b, int c) { int p1 = a / 100 % 10, p2 = a / 10 % 10, p3 = a / 1 % 10; int p4 = b / 100 % 10, p5 = b / 10 % 10, p6 = b / 1 % 10; int p7 = c / 100 % 10, p8 = c / 10 % 10, p9 = c / 1 % 10; int k[10]; k[1] = p1; k[2] = p2; k[3] = p3; k[4] = p4; k[5] = p5; k[6] = p6; k[7] = p7; k[8] = p8; k[9] = p9; sort(k + 1, k + 10); return k[1] == 1 && k[2] == 2 && k[3] == 3 && k[4] == 4 && k[5] == 5 && k[6] == 6 && k[7] == 7 && k[8] == 8 && k[9] == 9; } int main() { for (int i = 1; i <= 999; i++) { if (check(i, i * 2, i * 3)) { printf("%d %d %d\n", i, i * 2, i * 3); } } return 0; }
-
2
枚举大法yyds
#include <stdio.h> int main() { int a,b,c; for(a=123;a<=333;a++) { b=a*2; c=a*3; if((a/100+a/10%10+a%10+b/100+b/10%10+b%10+c/100+c/10%10+c%10==1+2+3+4+5+6+7+8+9)&&((a/100)*(a/10%10)*(a%10)*(b/100)*(b/10%10)*(b%10)*(c/100)*(c/10%10)*(c%10)==(1)*(2)*(3)*(4)*(5)*(6)*(7)*(8)*(9))) printf("%d %d %d\n",a,b,c); } return 0; }
-
1
思路:本题可以运用暴力枚举法,因为题目中有9个数字,所组成的3个三位数a,b,c的各个位数上的数的乘积与这已知的9个数的乘积相等,并且b=2a,c=3a。从能组成的最小三位数开始循坏,找满足条件的数即可。
代码如下: #include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c; for(int a=123;a<=330;a++) { b=2*a; c=3*a; if((a%10)*(a/10%10)*(a/100%10)*(b%10)*(b/10%10)*(b/100%10)*(c%10)*(c/10%10)*(c/100%10)==1*2*3*4*5*6*7*8*9) cout<<a<<" "<<b<<" "<<c<<endl; } return 0;
}
- 1
信息
- ID
- 1758
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 3
- 标签
- 递交数
- 229
- 已通过
- 125
- 上传者