Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.71 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.Arrays;
  3.  
  4. public class s2011_r1c_b {
  5.     public static void main(String[] args) throws IOException {
  6.         new s2011_r1c_b().run();
  7.     }
  8.     int nextInt() throws IOException {
  9.         in.nextToken();
  10.         return (int) in.nval;
  11.     }
  12.  
  13.     StreamTokenizer in;
  14.     Writer writer;
  15.     Reader reader;
  16.  
  17.     void run() throws IOException {
  18.         boolean oj = System.getProperty("ONLINE_JUDGE") != null;
  19.         reader = oj ? new InputStreamReader(System.in, "ISO-8859-1") : new FileReader("input/is2011_r1c_b.txt");
  20.         writer = oj ? new OutputStreamWriter(System.out, "ISO-8859-1") : new FileWriter("output/os2011_r1c_b.txt");
  21.         in = new StreamTokenizer(new BufferedReader(reader));
  22.         PrintWriter out = new PrintWriter(writer);
  23.         int T = nextInt();
  24.         int cnt = 1;
  25.         while (cnt <=T) {
  26.             int L = nextInt();
  27.             int t = nextInt();
  28.             int N = nextInt();
  29.             int[] arr = new int[N + 1];
  30.             int C = nextInt();
  31.             int[] koeff = new int[C];
  32.  
  33.             for (int i = 0 ; i < C; i++)
  34.                 koeff[i] = nextInt();
  35.  
  36.  
  37.             int j = 0;
  38.             for (int i = 1; i < arr.length; i++) {
  39.                 if (j == koeff.length)
  40.                     j = 0;
  41.                 arr[i] = koeff[j] ;
  42.                 j++;
  43.             }
  44.             boolean[] starHasBooster = new boolean[arr.length];
  45.             // fill starHasBooster
  46.             int[] backKoeff = Arrays.copyOf(koeff, koeff.length);
  47.             Arrays.sort(backKoeff);
  48.             for (int i = backKoeff.length - 1; i > -1; i--) {
  49.                 for (j = arr.length - 1; j > 0; j--)
  50.                     if (arr[j] == backKoeff[i]) {
  51.                         starHasBooster[j - 1] = true;
  52.                         L--;
  53.                         if (L == 0) break;
  54.                     }
  55.                 if (L == 0) break;
  56.             }
  57.             double speed;
  58.             long time = 0;
  59.             for (int index = 1; index < arr.length; index++) {
  60.                 if (time < t) {
  61.                     if (time + arr[index] * 2 > t && starHasBooster[index - 1]) {
  62.                         double need = t - time;
  63.                         time += need ;
  64.                         time += arr[index] - need * 0.5;
  65.                     } else {
  66.                         time += arr[index] / 0.5;
  67.                     }
  68.                 } else {
  69.                     speed = starHasBooster[index - 1]? 1:0.5;
  70.                     time += arr[index] / speed;
  71.                 }
  72.             }
  73.  
  74.             out.println(String.format("Case #%d: ", cnt) + time);
  75.             cnt++;
  76.         }
  77.         out.flush();
  78.         out.close();
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement