import java.util.*; public class ESunLight { // from 5:37 to 18:17 static double starts = (5 + 37.0/60); static double ends = (18 + 17.0/60); /* * Based on the duration from sun rises 5:37 to sun set 18:16 the following method *@param float angle that represent the angle of the sun *@return time in float format */ static double angle2time(double angle){ return ( ( (ends - starts) * angle + starts * Math.PI ) / Math.PI ); } /* * Based on the duration from sun rises 5:37 to sun set 18:16 the following method *@param float time of day in float format *@return float angle the sun will be at that time */ static double time2angle(double time){ return (Math.PI * time - starts * Math.PI) / (ends - starts); } public static void main(String[] args){ String input = "3\n" + "6 4\n"+ "5 6 3 3 4\n"+ "302 401 601 303 501 0\n"+ "4\n" + "5 3\n"+ "4 5 7 8 5 4 3\n"+ "101 302 503 0\n"+ "0"; Scanner s = new Scanner( input); List lst = new ArrayList(); int ac = 1; while(s.hasNext()){ int N = s.nextInt(); if(N ==0) break; int width = s.nextInt(); int height = s.nextInt(); float lDist = 0; float rDist = 0; for(int i=1;i<=N;i++){ int apts = s.nextInt(); Building b = new Building(i,apts,width,height); if( i == N){ b.setLeft( lDist); b.setRight(0); lst.add(b); break; } rDist = s.nextInt(); lst.add(b); b.setRight(rDist); if(i != 1) b.setLeft( lDist); lDist = rDist; } List lst2 = new ArrayList(); int aptNo = 10;//any non zero value while( true ){ aptNo = s.nextInt(); if(aptNo != 0) lst2.add(aptNo); else break; } System.out.println("Apartment Complex:" + ac++); process(lst,lst2); lst.clear(); lst2.clear(); } } static void process(List lst, List cases){ for(int i=0;i lst.get(apt.complex-1).apts){ System.out.println(" Does not exist"); }else{ printSunLight(apt,lst) ; } } } public static void printSunLight(Apt apt, List lst){ //check if the apt is east apt if(isEast(lst,apt)){ System.out.print(toTime(starts) + "-" ); //find the starting time System.out.println(sunSet(lst,apt)); } //check if the apt is west apt if(isWest(lst,apt)){ System.out.print(sunRise(lst,apt)); System.out.println(" - " + toTime(ends)); } if(!isEast(lst,apt) && !isWest(lst,apt)){ System.out.print(sunRise(lst,apt)); System.out.println( " - " + sunSet(lst,apt)); } } public static boolean isEast(List lst, Apt apt){ //if the apartment in the first complex from left if ( lst.get(0).id == apt.complex) return true; //or if the apartment is the tallest among all apartments in left //side complexes int c = apt.complex; for(int i=c-1;i>=1;i--){ if(lst.get(i-1).apts >= apt.aptNo) return false; } return true; } public static boolean isWest(List lst, Apt apt){ //if the apartment in the first complex from right if ( lst.get(lst.size()-1).id == apt.complex) return true; //or if the apartment is the tallest among all apartments in right //side complexes int c = apt.complex; for(int i=c;i= apt.aptNo) return false; } return true; } public static String sunRise(List lst, Apt apt){ int c = apt.complex; float max = 0; double maxAngle = 0; Building curBuilding = lst.get(apt.complex-1); double v = curBuilding.leftDist; for(int i=c-1;i>=1;i--){ Building bb = lst.get(i-1); float m = bb.getBuildingHeight(); double y = (bb.apts - apt.aptNo + 1)* curBuilding.aptHeight ; double x = v; double xy = y/x; double angle = Math.atan(xy) ; v += bb.leftDist + bb.aptWidth ; if(maxAngle < angle) maxAngle = angle; if( m > max) max = m; } return toTime( angle2time(maxAngle)); } public static String toTime(double f){ int hours = (int)f; double dMinutes = (f - (int) f) * 60.0; int minutes = (int) (( f - (int) f) * 60f); int seconds = (int) ( (dMinutes - minutes) * 60.0); return " " + (hours <10 ? "0" + hours : hours) + ":" + (minutes <10? "0" + minutes : minutes) +":" + (seconds < 10? "0" + seconds : seconds) + " "; } public static String sunSet(List lst, Apt apt){ int c = apt.complex; float max = 0; double maxAngle = 0; Building curBuilding = lst.get(apt.complex-1); double v = curBuilding.rightDist; for(int i=c;i max) max = m; } return toTime(angle2time(Math.PI - maxAngle)); } static Apt getApt(int aptNo){ return new Apt( aptNo % 100, aptNo /100); } } class Apt{ int complex; int aptNo; public Apt(int c, int no){ this.complex = c; this.aptNo = no; } public String toString(){ return "Apartment " + aptNo + "" + ( complex < 10 ? ("0" + complex) : complex ); } } class Building{ int id ; int apts;//number of appartments float leftDist = 0; float rightDist = 0; float aptWidth; float aptHeight; public Building(int id, int apt, float w, float h){ this.id = id; this.apts = apt; this.aptHeight = h; this.aptWidth = w; } public float getLength(){ return aptHeight * apts;} public void setLeft(float f){ this.leftDist = f;} public void setRight(float f){ this.rightDist = f;} public String toString(){ return leftDist + " Building ( " + id + " -->" + apts + " floors)" + rightDist; } public boolean isCelingApt(Apt a){ return a.aptNo == apts; } public float getAptHeight(Apt a){ return aptHeight * ( a.aptNo - 1); } public boolean equals(Object obj){ Building b = (Building) obj; return b.id == b.id; } public float getBuildingHeight(){ return aptHeight * apts; } }