codeforces Expecting Trouble

October 2, 2013
CodeForces

link:http://codeforces.com/contest/345/problem/A

写完这道题目才发现这场比赛只能用Ada语言提交==

好吧,逗我玩呢

考的是数学期望公式,二项分布的期望E=np

C++代码:(我可不会Ada……=_=)

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;
int main(void)
{
  char a[51];
  double p;
  #ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  #endif // ONLINE_JUDGE
  while (~scanf("%s%lf", a, &p))
  {
    int len = strlen(a);
    int cnt = 0;
    int cnt1 = 0;
    for (int i = 0; i < len; ++i)
    {
      if (a[i] == '1') cnt++;
      else if (a[i] == '?') cnt1++;
    }
    double Cnt = (double)cnt + p * (double)cnt1;
    printf("%.5lf\n", Cnt/(double)len);
  }

  return 0;
}

从今天起,每天一到两题。

comments powered by Disqus