当前位置:网站首页>码蹄集 - MT2165 - 小码哥的抽卡之旅1
码蹄集 - MT2165 - 小码哥的抽卡之旅1
2022-08-04 16:34:00 【Tisfy】
小码哥的抽卡之旅1
时间限制:1秒
空间限制:128M
题目描述
小码哥最近迷上了一款抽卡游戏。单抽出金的概率是0.6%,如果前89发都不出金,则90发必出金。小天目前存了一些抽数,想要你帮他算算他出金的概率。
输入描述
一个整数n,表示小码哥的抽数
数据范围
1<=n<=90
输出描述
一个百分数p,表示出金的概率,保留六位小数(按所给样例)
样例一
输入
1
输出
0.600000%
题目分析
好像和原神的抽卡一模一样
抽 0 0 0次中奖的概率是 0 0 0,不中奖的概率是 1 1 1
抽 1 1 1次中奖的概率是 1 × 0.006 = 0.006 1\times 0.006 = 0.006 1×0.006=0.006,不中的概率是 1 − 0.006 = 0.994 1 - 0.006 = 0.994 1−0.006=0.994
2 2 2次抽奖机会能中奖的概率是 0.006 + 0.994 × 0.006 = 0.011964 0.006 + 0.994\times 0.006 = 0.011964 0.006+0.994×0.006=0.011964
⋯ \cdots ⋯
注意,我描述 2 2 2次抽奖的时候,说的不是抽2次中奖的概率
。
两次抽奖机会
不等于抽2次中奖
两次抽奖机会
是指最多抽两次,哪一次中奖都可以
抽2次中奖
是指前 1 1 1次没中奖,第 2 2 2次中奖了
AC代码
其实做题的时候我忘特判 90 90 90发必中了, 90 90 90次机会能中奖的概率是 41.819882 % 41.819882\% 41.819882%,但是AC了。AC代码不等于正确代码
/* * @Author: LetMeFly * @Date: 2022-08-03 18:30:18 * @LastEditors: LetMeFly * @LastEditTime: 2022-08-03 18:33:03 */
#include <bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << #x << " = " << x << endl
#define fi(i, l, r) for (int i = l; i < r; i++)
#define cd(a) scanf("%d", &a)
typedef long long ll;
int main() {
int n;
double get = 0, notget = 1 - get;
cin >> n;
for (int i = 0; i < n; i++) {
get += notget * 0.006;
notget = 1 - get;
}
printf("%.6lf%\n", get * 100);
return 0;
}
正确代码
/* * @Author: LetMeFly * @Date: 2022-08-04 09:43:00 * @LastEditors: LetMeFly * @LastEditTime: 2022-08-04 09:43:02 */
#include <bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << #x << " = " << x << endl
#define fi(i, l, r) for (int i = l; i < r; i++)
#define cd(a) scanf("%d", &a)
typedef long long ll;
int main() {
int n;
double get = 0, notget = 1 - get;
cin >> n;
for (int i = 0; i < n; i++) {
get += notget * 0.006;
notget = 1 - get;
}
printf("%.6lf%\n", n == 90 ? double(1) : get * 100);
return 0;
}
方法二
其实也可以不用这么麻烦,直接枚举每一次不中奖的概率,代码更简短
n n n次都不中的概率是 ( 1 − 0.006 ) n (1-0.006)^n (1−0.006)n,因此答案为 1 − ( 1 − 0.006 ) n 1 - (1 - 0.006) ^ n 1−(1−0.006)n
int n;
cin >> n;
printf("%.6lf%\n", n == 90 ? double(1) : 1 - pow(1 - 0.006, n));
虽然代码可以复制,但最好还是自己理解后再敲哦
原创不易,转载请附上原文链接哦~
Tisfy:https://letmefly.blog.csdn.net/article/details/126153308
边栏推荐
猜你喜欢
随机推荐
gcc7.5.0编译ceres-solver报错‘is_trivially_default_constructible’ is not a member of ‘std’
寻找消失的类名
从正负样本解耦看对比学习为何需要large batch size训练Ddcoupled Contrastive learning (DCT)
张乐:研发效能的黄金三角及需求与敏捷协作领域的实践|直播回顾
花了半个月,终于把一线大厂高频面试题做成合集了
EMQ云端与局域网实现桥接功能
人造肉在中国还有未来吗?
DMS 有接口获取每个实例下的数据库列表吗
MetaAI科学家解读最新模型:200+语言互译,扩充千倍翻译数据,全球元宇宙用户自由交流
博云入选Gartner中国云原生领域代表性厂商
JVM Tuning-GC Fundamentals and Tuning Key Analysis
全差分运放:THS4140
SAP 电商云 Spartacus UI SSR 单元测试里的 callFake
MySQL学习之运算符
软考 --- 软件工程(2)软件开发方法
湖北移动中兴B860AV2.1_S905L_线刷固件包
Mobile Hisense IP102H_905L3-B_wire brush firmware package
[TA-Frost Wolf_may-"Hundred Talents Project"] Art 2.7 Metallic and Speculer Process
Minecraft 我的世界 .minecraft下的各个文件夹的用处
\/ PN的综合实验