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; }