Don't like ads? PRO users don't see any ads ;-)
Guest

GCJ 2012 Round 1A - a.cpp

By: allocator on Apr 27th, 2012  |  syntax: C++  |  size: 0.64 KB  |  hits: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int T, A, B;
  8. vector<double> p;
  9. int main(){
  10.         scanf("%d", &T);
  11.         for (int testcase = 0; testcase < T; ++ testcase){
  12.                 scanf("%d%d", &A, &B);
  13.                 p.resize(A);
  14.                 for (int i = 0; i < A; ++ i)
  15.                         scanf("%lf", &p[i]);
  16.                 double ans = B + 2, prob;
  17.                 double P = 1;
  18.                 for (int k = 0; k < A; ++ k){
  19.                         P *= p[k];
  20.                         int cnt1 = (A - k - 1 + B - k);
  21.                         int cnt2 = (cnt1 + B + 1);
  22.                         prob = P * cnt1 + (1 - P) * cnt2;
  23.                         ans = min(ans, prob);
  24.                         //printf ("k = %d, corr = %d, incorr = %d -- %lf\n", k, cnt1, cnt2, prob);
  25.                 }
  26.                 printf("Case #%d: %.7lf\n", testcase + 1, ans);
  27.         }
  28.         return 0;
  29. }