中国地质大学(武汉)第十九届程序设计大赛 - F - 抓住仿生泪滴
令 表示前 个人中被鲨死的人数的期望
则有两种情况:
- :那么 这个人不是仿生泪滴,那么我们不会鲨任何人
- :那么 这个人会和之前的某个人一起被鲨,则可得转移方程
// Problem: 抓住仿生泪滴
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/35753/F
// Memory Limit: 262144 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i(a); i <= b; i ++)
#define dec(i, a, b) for(int i(a); i >= b; i --)
#ifdef LOCAL
#include <debugger>
#else
#define debug(...) 42
#endif
template <typename T> inline void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> inline void chkmin(T &x, T y) { x = min(x, y); }
void solve() {
int n; cin >> n;
vector<int> a(n);
for(int &x: a) cin >> x;
vector<double> f(n);
for(int i = 1; i < n; i ++ ) {
if(a[i]) f[i] = f[i - 1];
else f[i] = f[i - 1] + 1 + (i - f[i - 1]) / (i);
}
cout << f.back();
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(6);
solve();
return 0;
}
/*
*
* ┏┓ ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃ ┃
* ┃ ━ ┃ ++ + + +
* ████━████+
* ◥██◤ ◥██◤ +
* ┃ ┻ ┃
* ┃ ┃ + +
* ┗━┓ ┏━┛
* ┃ ┃ + + + +Code is far away from
* ┃ ┃ + bug with the animal protecting
* ┃ ┗━━━┓ 神兽保佑,代码无bug
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛ + + + +
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛+ + + +
*/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现