33,008
社区成员
发帖
与我相关
我的任务
分享
public class Problem {
public static void solve(int n) {
int[] edge = new int[n * (n - 1) / 2];
int ei = 1;
int m = 0;
for (int va = 2; va < n; va++) {
int base = 0;
for (int vb = 1; vb < va; vb++) {
for (int vc = 0; vc < vb; vc++) {
int ebc = base + vc;
int eac = ei + vc;
if (edge[ebc] == 0 && edge[eac] == 0) {
edge[ebc] = edge[eac] = edge[ei + vb] = 1;
m++;
System.out.printf("%d, %d, %d\n", vc, vb, va);
break;
}
}
base += vb;
}
ei += va;
}
System.out.printf("When n = %d, m must be less than or equal to %d.\n", n, m);
}
public static void main(String[] args) {
Problem.solve(9);
}
}