baishu12 @ 2024-03-23 18:10:21
我的代码
#include <bits/stdc++.h>
using namespace std;
int t[11];
int check_a(double x) {
int i = x;
int b = i / 100;
int s = i % 100 / 10;
int g = i % 10;
if (t[b]) {
return 0;
}
t[b] = 1;
if (t[s]) {
return 0;
}
t[s] = 1;
if (t[g]) {
return 0;
}
t[g] = 1;
return 1;
}
int main() {
int a, b, c;
bool flag = 0;
cin >> a >> b >> c;
for (int i = 123; i <= 987; i++) {
double x = (i * 1.0) / a;
if ((b * x) != int(b * x)) {
continue;
}
if ((c * x) != int(c * x)) {
continue;
}
if (check_a(i) and check_a(b * x) and check_a(c * x)) {
cout << i << " " << b *x << " " << c *x << endl;
flag = 1;
for (int j = 1; j <= 9; j++) {
t[j] = 0;
}
} else {
for (int j = 1; j <= 9; j++) {
t[j] = 0;
}
continue;
}
}
if (!flag) {
cout << "No!!!";
}
return 0;
}
卡在#7死活过不了,Wrong Answer.wrong answer Too many lines. 我下载了测试点信息,输入是123 456 789,我的程序输出是123 456 789
这还不算玄学的,我用我老师代码测了下,在洛谷AC了,我在本地运行我老师的代码,输入123 456 789,输出竟然也是123 456 789,连换行都不差
我老师的代码
#include <bits/stdc++.h>
using namespace std;
int num[10];
bool fen(double a) {
int b = a;
while (b >= 1) {
if (num[b % 10] == 1) { //已经使用
return 0;
} else {
num[b % 10] = 1;
}
b /= 10;
}
return 1;
}
int main() {
num[0] = 1;
int A, B, C;
int flag = 0;
cin >> A >> B >> C;
for (double i = 123; i <= 987; i++) {
if (fen(i)) {
// cout << i / A *B;
if (i / A * B == int(i / A * B)) {
double er = i / A * B;
if (fen(er)) {
if (er / B * C == int(er / B * C)) {
double san = er / B * C;
if (fen(san)) {
cout << i << " " << er << " " << san << endl;
flag++;
}
}
}
}
}
memset(num + 1, 0, sizeof(num));
}
//cout << flag;
if (!flag) {
cout << "No!!!";
}
return 0;
}
本地测试截图如下:
by 杜都督 @ 2024-03-23 18:42:54
@baishu12 在 check_a()
第一行加上 if(x>987)return 0;
你原来的代码在#7的输出应该是
123 456 789
451 1672 2893
不太清楚你的环境下怎么只跑出了第一行
by baishu12 @ 2024-03-23 22:20:02
@杜都督 OK我试试
by baishu12 @ 2024-03-23 22:21:35
@杜都督 AC了感谢指教!