1 条题解
-
0
Java :
import java.util.Scanner; public class Main { static int [] x1,x2,y,a; static int n; static int count; public static void main(String[] args) { Scanner cin = new Scanner(System.in); n = cin.nextInt(); x1 = new int[42]; x2 = new int[42]; y = new int[42]; a = new int[20]; place(1); if(count == 0) { System.out.println("no"); } } public static void place(int x) { if(x > n) { count ++; for(int i = 1; i <= n; i ++) { System.out.print(a[i]); if(i != n) { System.out.print(" "); }else { System.out.println(); } } }else { for(int i = 1; i <= n; i ++) { if(x1[x+i] == 0 && x2[x-i+n] == 0 && y[i] == 0) { a[x] = i; y[i] = 1; x1[x+i] = 1; x2[x-i+n] = 1; place(x+1); y[i] = 0; x1[x+i] = 0; x2[x-i+n] = 0; } } } } }
- 1
信息
- ID
- 1228
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者