double res = 2+b

Remember there were 3 possible actions: keep typing, press backspace a
number of times and press enter and restart. The first two are
actually the same with the first one pressing backspace zero times.
But the third is one special case in which you press enter, type B
characters and press enter again. Thus B+2. The program holds this
value as the first option to compare it to all other expected values
to choose the minimum in line " if(res>r2) res=r2; "

double p=1

He is just initializing the probability, as 1 means 100%, he then
multiplies it for the individual probabilities of the case to obtain
the overall probability.  " p *= f;

int v = b+a+1-2*x;
double r2 = p*v+(1-p)*(v+b+1);

These lines actualy take one by one the probability, starting with the
case pressing backspace to delete all characters.


On May 1, 6:56 am, jitendra <[email protected]> wrote:
> import java.util.*;
>
> class A {
>     static Scanner scan;
>     public static double solve() {
>         int a = scan.nextInt();
>         int b = scan.nextInt();
>         double res = 2+b;
>         double p = 1;
>         for(int x=1;x<=a;x++) {
>             double f = scan.nextDouble();
>             p *= f;
>             int v = b+a+1-2*x;
>             double r2 = p*v+(1-p)*(v+b+1);
>             if(res>r2) res=r2;
>         }
>         return res;
>     }
>     public static void main(String[] args) {
>         scan = new Scanner(System.in);
>         int n = scan.nextInt();
>         for(int i=1;i<=n;i++) {
>             System.out.print("Case #"+i+": ");
>             System.out.println(solve());
>         }
>     }
>
> }
>
> i can not get
>
>         double res = 2+b;
>         double p = 1;
> and
>             int v = b+a+1-2*x;
>             double r2 = p*v+(1-p)*(v+b+1);
>             if(res>r2) res=r2;
>
> parts pls explain in detail ....... any answers and links are appreciable
> ........
>
>  A.java
> < 1KViewDownload

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en.

Reply via email to