// Google Code Jam 2014 Qualification Round B Cookie Clicker Alpha
// Problems: https://code.google.com/codejam/contest/2974486/dashboard#s=p1
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
//Google Code Jam
public class GoogleCode2 {
 private static MyScanner in;
 private static PrintStream out = System.out;
 private static PrintStream sysout = System.out;
 static int caseNum;
 private static void solve() throws IOException
 {
  PreCompute();
  int C = in.nextInt();
  for (int i = 0; i < C; i++) {
   caseNum = i + 1;
   out.print("Case #" + caseNum + ": ");
   solveCase();
  }
 }
 private static void PreCompute() {
 }
 static double minSecs;
 static double farmCost;
 static double F;
 static double X;
 private static void solveCase() throws IOException {
  farmCost = in.nextDouble();
  F = in.nextDouble();
  X = in.nextDouble();
  minSecs = Double.MAX_VALUE;
  Calculate(0, 2, 0);
  out.println(minSecs);
 }
 private static void Calculate(double curCookies, double cps,
   double curTimeSecs)
 {
  if (curCookies >= X) {
   if (curTimeSecs < minSecs)
    minSecs = curTimeSecs;
   return;
  }
  // keep producing without adding farms
  double addSecs = (X - curCookies) / cps;
  double totalSecs = addSecs + curTimeSecs;
  if (totalSecs < minSecs)
   minSecs = totalSecs;
  // add farm
  if (curCookies >= farmCost) {
   curCookies -= farmCost;
   addSecs = 0;
  }
  else {
   addSecs = (farmCost - curCookies) / cps;
   curCookies = 0;
  }
  curTimeSecs += addSecs;
  // if (Math.abs(curTimeSecs - minSecs) < 1e-7)
  // return;
  out.println("" + curTimeSecs + " " + minSecs);
  if (curTimeSecs < minSecs) {
   Calculate(curCookies, cps + F, curTimeSecs);
  }
  else
   return;
 }
 public static void main(String[] args) throws IOException {
  // helpers for input/output
  boolean usingFileForIO = true;
  if (usingFileForIO) {
   // using input.txt and output.txt as I/O
   in = new MyScanner("E:\\zin.txt");
   out = new PrintStream("E:\\zout.txt");
  }
  else {
   in = new MyScanner();
   out = System.out;
  }
  solve();
 }
 // =====================================
 static class MyScanner {
  Scanner inp = null;
  public MyScanner() throws IOException
  {
   inp = new Scanner(System.in);
  }
  public MyScanner(String inputFile) throws IOException {
   inp = new Scanner(new FileInputStream(inputFile));
  }
  public int nextInt() throws IOException {
   return inp.nextInt();
  }
  public long nextLong() throws IOException {
   return inp.nextLong();
  }
  public double nextDouble() throws IOException {
   return inp.nextDouble();
  }
  public String nextString() throws IOException {
   return inp.next();
  }
  public String nextLine() throws IOException {
   return inp.nextLine();
  }
 }
}
No comments:
Post a Comment