Advertisement
walterb1

Untitled

Apr 9th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. /*FILE 1*/
  2. package Stalls;
  3.  
  4. import java.util.Comparator;
  5. import java.util.PriorityQueue;
  6. import java.lang.Long;
  7. import java.lang.Math;
  8.  
  9. public class Distance {
  10.     private PriorityQueue<Long> dist;
  11.     private long k;
  12.     private long n;
  13.    
  14.     public Distance(long n, long k)
  15.     {
  16.         this.n = n;
  17.         this.k = k;
  18.         this.dist = new PriorityQueue<Long>(Comparator.reverseOrder());
  19.     }
  20.    
  21.     public long[] place()
  22.     {
  23.         long[] lsrs = new long[2];
  24.         long i, pos, dim1, dim2;
  25.        
  26.         this.dist.add(n);
  27.        
  28.         for(i = 0; i < k; i++)
  29.         {
  30.             pos = this.dist.poll();
  31.             dim1 = (long)Math.ceil((double)(pos - 1) / 2);
  32.             dim2 = (long)Math.floor((double)(pos - 1) / 2);
  33.             lsrs[0] = dim1;
  34.             lsrs[1] = dim2;
  35.             this.dist.add(dim1);
  36.             this.dist.add(dim2);
  37.         }
  38.        
  39.         return lsrs;
  40.     }
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47. /*FILE 2*/
  48. package Stalls;
  49.  
  50. import java.util.*;
  51. import java.io.*;
  52.  
  53. public class Program {
  54.  
  55.     public static void main(String[] args)
  56.     {
  57.         long n, k;
  58.         long[] lsrs;
  59.         int ncases, i;
  60.         Distance d;
  61.        
  62.         File fin = new File("C-small-2-attempt0.in");
  63.        
  64.         try
  65.         {
  66.             Scanner in = new Scanner(fin);
  67.             PrintWriter out = new PrintWriter("output.txt");
  68.             ncases = in.nextInt();
  69.            
  70.             for(i = 1; i <= ncases; i++)
  71.             {
  72.                 n = in.nextLong();
  73.                 k = in.nextLong();
  74.                
  75.                 d = new Distance(n, k);
  76.                 lsrs = d.place();
  77.                 out.println("Case #" +  i + ": " + lsrs[0] + " " + lsrs[1] + "\n");
  78.                 System.out.println("Case #" +  i + ": " + lsrs[0] + " " +  lsrs[1] + "\n");
  79.             }
  80.             out.close();
  81.             in.close();
  82.         }
  83.         catch(FileNotFoundException e)
  84.         {
  85.             System.out.println("Can't open file\n");
  86.         }
  87.        
  88.         return;
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement