|
| 1 | +```java |
| 2 | + |
| 3 | +import java.util.*; |
| 4 | +import java.io.*; |
| 5 | + |
| 6 | +class Point{ |
| 7 | + double x, y; |
| 8 | + Point(double x, double y){ |
| 9 | + this.x = x; |
| 10 | + this.y = y; |
| 11 | + } |
| 12 | +} |
| 13 | + |
| 14 | +class Main { |
| 15 | + |
| 16 | + // IO field |
| 17 | + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 18 | + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); |
| 19 | + static StringTokenizer st; |
| 20 | + |
| 21 | + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} |
| 22 | + static int nextInt() {return Integer.parseInt(st.nextToken());} |
| 23 | + static long nextLong() {return Long.parseLong(st.nextToken());} |
| 24 | + static void bwEnd() throws Exception {bw.flush();bw.close();} |
| 25 | + |
| 26 | + // Additional field |
| 27 | + static double[] A = new double[8]; |
| 28 | + static int ans = 0; |
| 29 | + |
| 30 | + static int ccw(Point a, Point b, Point c) { |
| 31 | + double r = (a.x*b.y + b.x*c.y + c.x*a.y) - (b.x*a.y + c.x*b.y + a.x*c.y); |
| 32 | + return r > 0 ? 1 : (r < 0 ? -1 : 0); |
| 33 | + } |
| 34 | + |
| 35 | + static void sol(int choose, List<Double> arr) { |
| 36 | + if(arr.size() == 8) { |
| 37 | + for(int i=0;i<8;i++) { |
| 38 | + Point a = new Point(0,arr.get(i)); |
| 39 | + Point b = new Point(arr.get((i+1)%8) / Math.sqrt(2), arr.get((i+1)%8) / Math.sqrt(2)); |
| 40 | + Point c = new Point(arr.get((i+2)%8), 0); |
| 41 | + if(ccw(a,b,c) > 0) return; |
| 42 | + } |
| 43 | + ans++; |
| 44 | + return; |
| 45 | + } |
| 46 | + for(int i=0;i<8;i++) { |
| 47 | + if((choose & (1<<i)) != 0) continue; |
| 48 | + arr.add(A[i]); |
| 49 | + sol(choose | (1<<i), arr); |
| 50 | + arr.remove(arr.size()-1); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + public static void main(String[] args) throws Exception { |
| 55 | + |
| 56 | + nextLine(); |
| 57 | + for(int i=0;i<8;i++) A[i] = nextInt(); |
| 58 | + sol(0, new ArrayList<>()); |
| 59 | + |
| 60 | + bw.write(ans+"\n"); |
| 61 | + |
| 62 | + bwEnd(); |
| 63 | + } |
| 64 | + |
| 65 | +} |
| 66 | + |
| 67 | +``` |
0 commit comments