Guest User

Untitled

a guest
Dec 3rd, 2022
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3. import java.util.HashMap;
  4.  
  5. public class Solution
  6. {      
  7.     private static class Pair
  8.     {
  9.         int n, s;
  10.         double vol;
  11.        
  12.         public Pair(int n, int s)
  13.         {
  14.             this.n = n;
  15.             this.s = s;
  16.             this.vol = Math.sqrt(n*n - s*s/3.0) * s * s * Math.sqrt(3) / 12;
  17.         }
  18.        
  19.         @Override
  20.         public String toString()
  21.         {
  22.             return "(" + n + ", " + s + ")";
  23.         }
  24.     }
  25.    
  26.     private static class Quad
  27.     {
  28.         Pair p1, p2;
  29.         double vol;
  30.        
  31.         public Quad(Pair p1, Pair p2)
  32.         {
  33.             this.p1 = p1;
  34.             this.p2 = p2;
  35.             this.vol = p1.vol + p2.vol;
  36.         }
  37.        
  38.         @Override
  39.         public String toString()
  40.         {
  41.             return "(" + p1 + ", " + p2 + ")";
  42.         }
  43.     }
  44.    
  45.     public static void main(String[] args)
  46.     {
  47.         ArrayList<Pair> tetrs = new ArrayList<Pair>();
  48.         for(int n = 1; n <= 100; n++)
  49.         {
  50.             for(int s = n; s <= 100; s++)
  51.             {
  52.                 if(n*n > s*s/3.0)
  53.                     tetrs.add(new Pair(n, s));
  54.             }
  55.         }
  56.        
  57.         ArrayList<Quad> quads = new ArrayList<Quad>();
  58.         for(int i = 0; i < tetrs.size(); i++)
  59.             for(int j = i; j < tetrs.size(); j++)
  60.                 quads.add(new Quad(tetrs.get(i), tetrs.get(j)));
  61.        
  62.         Collections.sort(tetrs, (p1, p2) -> Double.compare(p1.vol, p2.vol));
  63.         Collections.sort(quads, (q1, q2) -> Double.compare(q1.vol, q2.vol));
  64.        
  65.         int tIdx = 0;
  66.         int qIdx = 0;
  67.         while(true)
  68.         {
  69.             if(tIdx >= tetrs.size())
  70.                 break;
  71.            
  72.             Pair tetr = tetrs.get(tIdx);
  73.             Quad quad = quads.get(qIdx);
  74.            
  75.             if(Math.abs(tetr.vol - quad.vol) < 0.0001)
  76.             {
  77.                 System.out.println(tetr);
  78.                 System.out.println(quad);
  79.                 System.out.println();
  80.             }
  81.            
  82.             if(tetr.vol <= quad.vol)
  83.                 tIdx++;
  84.             else
  85.                 qIdx++;
  86.         }
  87.     }
  88. }
  89.  
Advertisement
Add Comment
Please, Sign In to add comment