Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.HashMap;
- public class Solution
- {
- private static class Pair
- {
- int n, s;
- double vol;
- public Pair(int n, int s)
- {
- this.n = n;
- this.s = s;
- this.vol = Math.sqrt(n*n - s*s/3.0) * s * s * Math.sqrt(3) / 12;
- }
- @Override
- public String toString()
- {
- return "(" + n + ", " + s + ")";
- }
- }
- private static class Quad
- {
- Pair p1, p2;
- double vol;
- public Quad(Pair p1, Pair p2)
- {
- this.p1 = p1;
- this.p2 = p2;
- this.vol = p1.vol + p2.vol;
- }
- @Override
- public String toString()
- {
- return "(" + p1 + ", " + p2 + ")";
- }
- }
- public static void main(String[] args)
- {
- ArrayList<Pair> tetrs = new ArrayList<Pair>();
- for(int n = 1; n <= 100; n++)
- {
- for(int s = n; s <= 100; s++)
- {
- if(n*n > s*s/3.0)
- tetrs.add(new Pair(n, s));
- }
- }
- ArrayList<Quad> quads = new ArrayList<Quad>();
- for(int i = 0; i < tetrs.size(); i++)
- for(int j = i; j < tetrs.size(); j++)
- quads.add(new Quad(tetrs.get(i), tetrs.get(j)));
- Collections.sort(tetrs, (p1, p2) -> Double.compare(p1.vol, p2.vol));
- Collections.sort(quads, (q1, q2) -> Double.compare(q1.vol, q2.vol));
- int tIdx = 0;
- int qIdx = 0;
- while(true)
- {
- if(tIdx >= tetrs.size())
- break;
- Pair tetr = tetrs.get(tIdx);
- Quad quad = quads.get(qIdx);
- if(Math.abs(tetr.vol - quad.vol) < 0.0001)
- {
- System.out.println(tetr);
- System.out.println(quad);
- System.out.println();
- }
- if(tetr.vol <= quad.vol)
- tIdx++;
- else
- qIdx++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment