The first question of the Microsoft 2017 Preparatory writing test

Source: Internet
Author: User
Tags pow

The first question of the

Microsoft 2017 Preparatory pen Questions AC code:

#include <vector> #include <math.h> #include <iostream> #include <iomanip> using namespace std;
    Double pm (int p,double Q, long N, int aa) {if (N = 0) return 0;
    Double p_org;
    if (N-1 > aa) p_org = 0;
        else{int a = Floor (P/pow (2,n-1));
    p_org = Double (a)/100.0;
    Vector<double> ans;
    Double tmp;
        if (p_org > 0) {ans.push_back (1+pm (P,Q,N-1,AA)) *p_org);
    TMP = (ans[0]/p_org)-1.0;
        } else{ans.push_back (0.0);
    TMP = PM (P,Q,N-1,AA);
    Double p = p_org;
    Double p_b = 1;
        for (int n=1;n<100;n++) {ans.push_back (n+1+tmp);
        Ans[n] = ans[n] * p_b * (1-P);
            if (p+q>=1) {Double an = 0;
            for (int i=0;i<ans.size (); i++) {a = An+ans[i];
        return to an;
        else {Ans[n] = ans[n]* (P+Q);
        } p_b = P_b * (1-p); p = P+ Q;
} return-1;
    int main () {int p,q,n;
    CIN >> P >> Q >> N;
    Long Maxx = N;
            for (int i=0;i<n;i++) {if (Pow (2,i) >= P) {maxx = i;
        Break
    Double ans = pm (p,q/100.0,n,maxx);
cout << setprecision (2) << setiosflags (ios::fixed) << ans << Endl; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.