import java.io.*; import java.util.StringTokenizer; public class Main { static String ReadLn (int maxLg) // utility function to read from stdin { byte lin[] = new byte [maxLg]; int lg = 0, car = -1; String line = ""; try { while (lg < maxLg) { car = System.in.read(); if ((car < 0) || (car == '\n')) break; lin [lg++] += car; } } catch (IOException e) { return (null); } if ((car < 0) && (lg == 0)) return (null); // eof return (new String (lin, 0, lg)); } public static void main (String args[]) // entry point from OS { Main myWork = new Main(); // create a dynamic instance myWork.Begin(); // the true entry point } void Begin() { String input; StringTokenizer st; while ((input = Main.ReadLn (255)) != null) { st=new StringTokenizer(input); int H=Integer.parseInt(st.nextToken()); int U=Integer.parseInt(st.nextToken()); int D=Integer.parseInt(st.nextToken()); int F=Integer.parseInt(st.nextToken()); if(H==0) { System.exit(0); } float previousheight=0; int days=1; while(true) { float climbingdistance=(U-((days-1)*U*(float)F/100)); float y=previousheight; if(climbingdistance > 0) { y=previousheight+climbingdistance; //System.out.println("y ="+y+" previousheight "+previousheight); } if(y>H) { System.out.println("success on day "+days); break; } if(y<=H && y>=0) { y=y-D; } if(y<0) { System.out.println("failure on day "+days); break; } days++; previousheight=y; } } } }
0 comments: