import java.util.Scanner; public class Triangles { public static final int MAX = 20; public static matches [] holeMatches = new matches[MAX]; public static triangle [] hole = new triangle[MAX]; public static triangle [] piece = new triangle[2*MAX]; public static line [] lines2 = new line[6*MAX]; public static int n; public static double cosine(point p1, point p2, point p3) // determine cosine between line formed from (p1,p2) and (p2,p3) { point pa = p1.sub(p2); point pb = p3.sub(p2); double lena = Math.sqrt(pa.x*pa.x + pa.y*pa.y); double lenb = Math.sqrt(pb.x*pb.x + pb.y*pb.y); return (pa.x*pb.x + pa.y*pb.y)/lena/lenb; } public static int findFit(double len1, double len2, double len3, int start) // check if a given set of lengths matches a triangle hole, starting at // hole start { double [] len = new double[3]; len[0] = len1; len[1] = len2; len[2] = len3; if (len[1] < len[0]) { double tmp = len[0]; len[0] = len[1]; len[1] = tmp; } if (len[2] < len[0]) { double tmp = len[0]; len[0] = len[2]; len[2] = tmp; } if (len[2] < len[1]) { double tmp = len[2]; len[2] = len[1]; len[1] = tmp; } for(int i=start; i 1) continue; if (holeMatches[i].nMatch == 0) return false; hole[i].used = true; hole[i].pieces[0] = holeMatches[i].matches[0].t1; hole[i].pieces[1] = holeMatches[i].matches[0].t2; removeTriangles(holeMatches[i].matches[0].t1, n); removeTriangles(holeMatches[i].matches[0].t2, n); count++; } } return true; } public static void main(String [] args) { int icase=0; for(int i=0; i 0 && lines2[k-1].length > len) { lines2[k] = lines2[k-1]; k--; } lines2[k] = new line(); lines2[k].length = len; lines2[k].t = i; lines2[k].v = j; } } findMatches(n); boolean solved = findSolution(n); // output results System.out.println("Case " + icase + ":"); if (solved) { for(int i=0; i sin1) { temp = p[1]; p[1] = p[2]; p[2] = temp; } } } class line { // used to store triangle sides public double length; public int t; // triangle which contains the line public int v; // starting vertex of line public boolean used; // whether it's been matched with another line }