Hello,
This should depends on the number if it's an odd or not:
double dx = Math.floor ((N-K) /lastPow) + 1; 

But I didn't test to confirm ...

On Monday, April 10, 2017 at 3:41:52 PM UTC+1, Nam Nguyen Hoang wrote:
> When i try to solve the "Bathroom Stalls" problem, I reach to this solution 
> (code in java below):
> 
>  public static String ProblemC(int caseNumber, Scanner in) {
>         String result = "Case #" + caseNumber + ": ";
>         double Ls = 0, Rs = 0;
> 
>         if (in.hasNext()) {
>             long N = in.nextLong(), K = in.nextLong();
>             if(K < N)
>             {
>                 double po = 1, powerof = 2, lastPow = 1;
>                 while (powerof <= K)
>                 {
>                     po++;
>                     lastPow = powerof;
>                     powerof = Math.pow(2, po);
>                 }
> 
>                 double dx = Math.floor ((N-K) /lastPow) + 1;
>                 println("power:" + po + " ;"  +powerof + " ;" + lastPow + " 
> (N-K)" + (N-K) + "dx:" + dx);
> 
>                 Ls = dx/2; Rs = Ls;
>                 if(dx%2==0) Rs--;
>             }
>         }
> 
> 
>         result += (long)Ls + " " + (long)Rs;
>         println(result);
>         return result + "\n";
>     }
> 
> It passed the 2 small dataset (all correct), but not the large one. I know my 
> method has some problems, but i can't find it. So i post here, and hope 
> someone can help me!

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/be999045-6f78-4ca0-bf22-d82c3e0f6e30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to