Codeforces Round #272 (Div. 2) 476B - Dreamoon and WiFi Solution
Problem Link: https://codeforces.com/problemset/problem/476/B
Solve in C++:
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
string a,b;
cin>>a>>b;
int i,pa=0,pb=0,q=0,cn=0;
for(i=0; i<a.size(); i++)
{
if(a[i]=='+')
pa++;
if(b[i]=='+')
pb++;
if(b[i]=='?')
q++;
}
double v=1<<q;
for(i=0; i<v; i++)
{
if(__builtin_popcount(i)+pb==pa)
cn++;
}
cout<<fixed<<setprecision(9)<<(double)cn/v<<endl;
}
No comments