数据类型使用 long,int 类型只能过 2/3 的用例,排查了好久,怎么看都感觉代码没问题,就是过不了后面的用例,把 x,y,z 的数据类型全改成 long 就好了
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextLine()) {
int n = in.nextInt();
long h = in.nextLong();
long[][] ints = new long[n][3];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
ints[i][j] = in.nextInt();
}
}
in.nextLine();
for (long[] i : ints) {
long x = i[0];
long y = i[1];
long z = (h << 1) - i[2];
long cd = gcd(gcd(x, y), z);
System.out.println((x / cd) + " " + (y / cd) + " " + (z / cd));
}
}
}
private static long gcd(long a, long b) {
a = Math.abs(a);
b = Math.abs(b);
while (b != 0) {
long temp = b;
b = a % b;
a = temp;
}
return a;
}
}


京公网安备 11010502036488号