codebytes: SPOJ BTCODE_H (Maths) Solution - Java
Test Case given- N = 2, K = 2. # of words containing only 0 and 1 that are of length 2 -> 4 00 01 10 11 00 00 4 nodes = 4 5 nodes = 8 ---------------------- = --------------------- = 4.25 16 16 Source (Java): import java.io.IOException; import java.io.InputStream; import java.util.InputMismatchException; public class BTCODE_HSimple { //Exponentiation by Repeated Sqauring public static double power(double a, int b){ if(b==0)return 1; if(b==1)return a; if(b%2==1){ return a*power(a*a, (b-1)/2); }else return power(a*a, b/2); } public static void main(String[] args){ int n = IO.nextInt(); while(n-->0){ int N = IO.nextInt(); int K = IO.nextInt(); double ans = 1; for(int i=1;i<=K;++i){ double p = power(0.5, i); ans += 1; double op = 1-p; for(int j=1;jRead full article from codebytes: SPOJ BTCODE_H (Maths) Solution - Java
No comments:
Post a Comment