Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*FILE 1*/
- package Stalls;
- import java.util.Comparator;
- import java.util.PriorityQueue;
- import java.lang.Long;
- import java.lang.Math;
- public class Distance {
- private PriorityQueue<Long> dist;
- private long k;
- private long n;
- public Distance(long n, long k)
- {
- this.n = n;
- this.k = k;
- this.dist = new PriorityQueue<Long>(Comparator.reverseOrder());
- }
- public long[] place()
- {
- long[] lsrs = new long[2];
- long i, pos, dim1, dim2;
- this.dist.add(n);
- for(i = 0; i < k; i++)
- {
- pos = this.dist.poll();
- dim1 = (long)Math.ceil((double)(pos - 1) / 2);
- dim2 = (long)Math.floor((double)(pos - 1) / 2);
- lsrs[0] = dim1;
- lsrs[1] = dim2;
- this.dist.add(dim1);
- this.dist.add(dim2);
- }
- return lsrs;
- }
- }
- /*FILE 2*/
- package Stalls;
- import java.util.*;
- import java.io.*;
- public class Program {
- public static void main(String[] args)
- {
- long n, k;
- long[] lsrs;
- int ncases, i;
- Distance d;
- File fin = new File("C-small-2-attempt0.in");
- try
- {
- Scanner in = new Scanner(fin);
- PrintWriter out = new PrintWriter("output.txt");
- ncases = in.nextInt();
- for(i = 1; i <= ncases; i++)
- {
- n = in.nextLong();
- k = in.nextLong();
- d = new Distance(n, k);
- lsrs = d.place();
- out.println("Case #" + i + ": " + lsrs[0] + " " + lsrs[1] + "\n");
- System.out.println("Case #" + i + ": " + lsrs[0] + " " + lsrs[1] + "\n");
- }
- out.close();
- in.close();
- }
- catch(FileNotFoundException e)
- {
- System.out.println("Can't open file\n");
- }
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement