import java.util.*; import java.net.*; import java.io.*; public class Lab5Server { static class Contorno { public static boolean f(double x, double y) { // Wings bottom if (Math.pow(x, 2.0) / 49.0 + Math.pow(y, 2.0) / 9.0 - 1.0 <= 0 && Math.abs(x) >= 4.0 && -(3.0 * Math.sqrt(33.0)) / 7.0 <= y && y <= 0) { return true; } // Wings top (with the fix of the formula there are missing parenthesis in the original if (Math.pow(x, 2.0) / 49.0 + Math.pow(y, 2.0) / 9.0 - 1.0 <= 0 && Math.abs(x) >= 3.0 && -(3.0 * Math.sqrt(33.0)) / 7.0 <= y && y >= 0) { return true; } // Tail if (-3.0 <= y && y <= 0 && -4.0 <= x && x <= 4.0 && (Math.abs(x)) / 2.0 + Math.sqrt(1.0 - Math.pow(Math.abs(Math.abs(x) - 2.0) - 1.0, 2.0)) - 1.0 / 112.0 * (3.0 * Math.sqrt(33.0) - 7.0) * Math.pow(x, 2.0) - y - 3.0 <= 0) { return true; } // Ears outside if (y >= 0 && 3.0 / 4.0 <= Math.abs(x) && Math.abs(x) <= 1.0 && -8.0 * Math.abs(x) - y + 9.0 >= 0) { return true; } // Ears inside if (1.0 / 2.0 <= Math.abs(x) && Math.abs(x) <= 3.0 / 4.0 && 3.0 * Math.abs(x) - y + 3.0 / 4.0 >= 0 && y >= 0) { return true; } // Chest if (Math.abs(x) <= 1.0 / 2.0 && y >= 0 && 9.0 / 4.0 - y >= 0) { return true; } // Shoulders if (Math.abs(x) >= 1.0 && y >= 0 && -(Math.abs(x)) / 2.0 - 3.0 / 7.0 * Math.sqrt(10.0) * Math.sqrt(4.0 - Math.pow(Math.abs(x) - 1.0, 2.0)) - y + (6.0 * Math.sqrt(10.0)) / 7.0 + 3.0 / 2.0 >= 0) { return true; } return false; } public static boolean containsPoint(double x, double y, double r) { return f(x/r*7,y/r*7); } } static class SocketProcessingThread extends Thread { private Socket socket; public SocketProcessingThread(Socket socket) { this.socket = socket; } public void run() { try { DataInputStream input = new DataInputStream(socket.getInputStream()); DataOutputStream output = new DataOutputStream(socket.getOutputStream()); while(true) { double x = input.readDouble(); double y = input.readDouble(); double r = input.readDouble(); output.writeInt(Contorno.containsPoint((int)x, (int)y, (int)r) ? 1 : 0); } } catch(Exception e) { } } } public static void main(String[] args) { try { ServerSocket ss = new ServerSocket(1927); Socket socket = null; while((socket = ss.accept()) != null) new SocketProcessingThread(socket).start(); } catch(IOException e) { e.printStackTrace(); } } }