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

Most View Post

Recent post

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.