/** *
Title:
* *Description:
* *Copyright: Copyright (c) 2005
* *Company:
* * @author not attributable * @version 1.0 */ import java.io.*; import java.lang.*; import java.util.*; public class castles { public static void main(String[] args) { try { FileReader fr = new FileReader("castles.in"); BufferedReader br = new BufferedReader(fr); String input = br.readLine(); // number of data sets int numSets = Integer.parseInt(input); // read in the data sets for (int i = 0; i < numSets; i++) { double w, h, m, d; int b; input = br.readLine(); String[] tokens = input.split("\\s"); w = Double.parseDouble(tokens[0]); h = Double.parseDouble(tokens[1]); m = Double.parseDouble(tokens[2]); d = Double.parseDouble(tokens[3]); b = Integer.parseInt(tokens[4]); // total area of the base double baseArea = (h - 2.0*m)*(w-2.0*m); // calculate moat double moatArea = w*h - (h - 2.0*m)*(w-2.0*m); double totalArea = w*h; double totalVolumeForBuildings = 0.0; // read in the buildings for (int k = 0; k < b; k++) { String buildingsRaw = br.readLine(); String[] buildings = buildingsRaw.split("\\s"); double buildH = Double.parseDouble(buildings[0]); double buildR = Double.parseDouble(buildings[1]); // Volume = Pi*R^2*h double volume = Math.PI * buildR * buildR * buildH; // add to the total area totalVolumeForBuildings += volume; // System.out.println("H: " + buildH + " R: " + buildR + " volume: " + volume + " total: " + totalVolumeForBuildings); } // calculate the other stuff // calculates the distance required to build the buildings double x = totalVolumeForBuildings / totalArea; // so if moat is 0, consider the whole thing a moat if (m == 0) { moatArea = baseArea; baseArea = 0; } double Moatdelta = (d) * (moatArea) / (baseArea + moatArea); double finalDelta = 0 - x + Moatdelta; double delta = finalDelta; // Display the output System.out.println("Data Set " + (i+1) + ":"); if (delta%(int)delta == 0) System.out.println((new java.text.DecimalFormat("#.##")).format(delta)+".00"); else System.out.println((new java.text.DecimalFormat("#.##")).format(delta)); } } catch (Exception e) { } } }