Help me in solving AOJ19 problem

My issue

2nd case fails ??

My code

import java.util.*;

class Codechef
{
	public static void main (String[] args)
	{
		Scanner read = new Scanner(System.in);
		int t = read.nextInt();
		for(int i=0; i<t; i++)
		{
		    ArrayList<Integer> face = new ArrayList<Integer>();
		    int n = read.nextInt();
		    int a = read.nextInt();
		    int b = read.nextInt();
		    // Update the code below to solve this problem
		    for(int k = 0;k<n;k++){
		        int c = read.nextInt();
		        face.add(c);
		    }
		    
		    
		    int count = 1;
		    int f = face.get(0);
		    for(int j =0;j<n;j++){
		       if(face.get(j) != f){
		        count = count + 1;
		    }
		        
		    }
		    
		    double p = Math.pow((1/count),n);
		    //double p = (a/count)*(b/count);
		    
		    System.out.println(String.format("%.10f",p));

		    
		    
		
		
	}
}
}

Learning course: Solve Programming problems using Java
Problem Link: CodeChef: Practical coding for everyone

@smparatwar
The logic is u have to count A and B in the array and suppose their count comes c1 and c2 then probability will be (c1 * c2)/(n * n ) where n is the size of the array.

Still the case
2 1 1
1 2
fails it gives result 0??

@smparatwar
for this c1 will be 1 and c2 will be 1 and n is 2 so 1*1/4 will be 0.25 .
just take the floating value!

1 Like