Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Arrays;
- public class s2011_r1c_b {
- public static void main(String[] args) throws IOException {
- new s2011_r1c_b().run();
- }
- int nextInt() throws IOException {
- in.nextToken();
- return (int) in.nval;
- }
- StreamTokenizer in;
- Writer writer;
- Reader reader;
- void run() throws IOException {
- boolean oj = System.getProperty("ONLINE_JUDGE") != null;
- reader = oj ? new InputStreamReader(System.in, "ISO-8859-1") : new FileReader("input/is2011_r1c_b.txt");
- writer = oj ? new OutputStreamWriter(System.out, "ISO-8859-1") : new FileWriter("output/os2011_r1c_b.txt");
- in = new StreamTokenizer(new BufferedReader(reader));
- PrintWriter out = new PrintWriter(writer);
- int T = nextInt();
- int cnt = 1;
- while (cnt <=T) {
- int L = nextInt();
- int t = nextInt();
- int N = nextInt();
- int[] arr = new int[N + 1];
- int C = nextInt();
- int[] koeff = new int[C];
- for (int i = 0 ; i < C; i++)
- koeff[i] = nextInt();
- int j = 0;
- for (int i = 1; i < arr.length; i++) {
- if (j == koeff.length)
- j = 0;
- arr[i] = koeff[j] ;
- j++;
- }
- boolean[] starHasBooster = new boolean[arr.length];
- // fill starHasBooster
- int[] backKoeff = Arrays.copyOf(koeff, koeff.length);
- Arrays.sort(backKoeff);
- for (int i = backKoeff.length - 1; i > -1; i--) {
- for (j = arr.length - 1; j > 0; j--)
- if (arr[j] == backKoeff[i]) {
- starHasBooster[j - 1] = true;
- L--;
- if (L == 0) break;
- }
- if (L == 0) break;
- }
- double speed;
- long time = 0;
- for (int index = 1; index < arr.length; index++) {
- if (time < t) {
- if (time + arr[index] * 2 > t && starHasBooster[index - 1]) {
- double need = t - time;
- time += need ;
- time += arr[index] - need * 0.5;
- } else {
- time += arr[index] / 0.5;
- }
- } else {
- speed = starHasBooster[index - 1]? 1:0.5;
- time += arr[index] / speed;
- }
- }
- out.println(String.format("Case #%d: ", cnt) + time);
- cnt++;
- }
- out.flush();
- out.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement