米哈游第三题
#米哈游##米哈游测试#考的时候出金公式推错了,后面改了改。输入0.006时,输出是104.55,记不得测试用例给的104.多少了,希望大佬们指点一下
#include
#include
using namespace std;
int main() {
double p;
double sum = 0.0;
vector a(91);
cin >> p;
a[0] = 1;
a[1] = p;
double tmp = a[1];
for (int i = 2; i <= 89; i++) {
a[i] = a[i-1] * (1 - p);
tmp += a[i];
}
a[90] = 1 - tmp;
//for (int i =1; i <= 90; i++) cout << a[i] << endl;
vector res(181);
res[1] = a[1] / 2;
for (int i = 2; i <= 180; i++) {
double tmp = 0.0;
for (int j = 1; j <= i; j++) {
if (j <= 90) tmp += a[j] * 0.5 * a[i - j];
}
res[i] = tmp;
}
//for (int i = 90; i <= 180; i++) cout << res[i] << endl;
for (int i = 1; i <= 180; i++) sum += i * res[i];
cout << sum;
}
#include
#include
using namespace std;
int main() {
double p;
double sum = 0.0;
vector
cin >> p;
a[0] = 1;
a[1] = p;
double tmp = a[1];
for (int i = 2; i <= 89; i++) {
a[i] = a[i-1] * (1 - p);
tmp += a[i];
}
a[90] = 1 - tmp;
//for (int i =1; i <= 90; i++) cout << a[i] << endl;
vector
res[1] = a[1] / 2;
for (int i = 2; i <= 180; i++) {
double tmp = 0.0;
for (int j = 1; j <= i; j++) {
if (j <= 90) tmp += a[j] * 0.5 * a[i - j];
}
res[i] = tmp;
}
//for (int i = 90; i <= 180; i++) cout << res[i] << endl;
for (int i = 1; i <= 180; i++) sum += i * res[i];
cout << sum;
}
全部评论
相关推荐
10-18 21:51
西安电子科技大学 C++ 点赞 评论 收藏
分享