2010年7月9日金曜日

TopCoder 練習

RabbitStepping(SRM 475 DIV1 Easy)

import java.util.*;
import java.lang.*;
import java.math.*;
public class RabbitStepping {
public double getExpected(String field, int r) {
int n=field.length();
int cnt=0, sum=0;
for(int i=0; i<1<<n; i++){
if(Integer.bitCount(i)==r){
int r1=0, r2=0;
for(int k=0; k<n; k++){
if((i>>k&1)==1){
if(k%2==0) r1++;
else r2++;
}
}
cnt+=r1%2+r2%2;
sum++;
}
}
return (double)cnt/sum;
}
}


// Powered by FileEdit
// Powered by TZTester 1.01 [25-Feb-2003]
// Powered by CodeProcessor

0 件のコメント: