ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

[HAOI2015]按位或

2022-01-23 17:01:37  阅读:146  来源: 互联网

标签:max min int 选到 HAOI2015 按位 siz define


[HAOI2015]按位或

min-max 容斥

记 \(\max\{S\}\) 表示 \(S\) 中每一数都被选到过的期望时间,\(\min\{S\}\) 表示 \(S\) 中出现至少一个数被选到的期望时间

答案显然为 \(\max\{U\}\) ,\(U= \{n \cdot 1\}\)

直接求 \(\max\{U\}\) 不好求,利用 min-max 容斥转化为求 \(\min\{S\}\)

\(\max\{S\} = \sum_{T \subseteq S} (-1)^{|T| + 1} \cdot \min\{T\}\)

记 \(f(S)\) 表示每一秒选择 \(S\) 子集的概率

则第一次选到 \(S\) 子集的期望时间,也就是 \(\min\{S\}\) 为 :

\(\min\{S\} = \sum_{i = 1} ^ {+\infty} i \cdot (1 - f(\complement_US)) \cdot f ^ {i - 1}(\complement_US)\)

注意 :\(1 - f(\complement_US) \not = f(S)\)

左边是选到的有 \(S\) 内的数的概率,而右边是选到的全是 \(S\) 中数(也就是选到 \(S\) 子集)的概率,显然左边概率比右边大

发现 \(\min\{S\}\) 满足几何分布,于是 \(\min\{S\} = \frac{1}{1 - f(\complement_US)}\)

几何分布可以理解为:

抽一个物品,每次中奖率为 1% ,那么期望抽100次就能抽中(然而现实显然不是这样,但我们只管期望)

考虑求 \(f(S)\)

记 \(g(S)\) 表示选择 \(S\) 的概率,则

\(f(S) = \sum_{T\subseteq S} g(T)\)

发现是个 FWTOR,得以求解

#include <bits/stdc++.h>
#define re register
// #define int long long
// #define pair pair<int, int>
// #define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout);
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 21], *p1 = buf, *p2 = buf;
using namespace std;
inline int read()
{
    re int x = 0, f = 0;
    re char ch = getchar();
    while (!isdigit(ch)) {if (ch == '-') f = 1; ch = getchar();}
    while (isdigit(ch)) {x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return f ? -x : x;
}
inline string getstr()
{
    string res = "";
    re char ch = getchar();
    while (isspace(ch)) ch = getchar();
    while (!isspace(ch)) res.push_back(ch), ch = getchar();
    return res;
}
const int N = 1.1e6 + 6;
const double eps = 1e-6;
namespace FastWT
{
    #define OR 0
    #define AND 1
    #define XOR 2
    template<short op> inline void FWT(double *A, const int &siz, const bool &flag)
    {
        for (re int len = 1; len < siz; len <<= 1)
        {
            const int rlen = len << 1;
            for (re int i = 0; i < siz; i += rlen)
                for (re int j = 0; j < len; ++j)
                {
                    double x = A[i + j], y = A[i + j + len];
                    if (op == OR)
                        A[i + j] = x,
                        A[i + j + len] = y + (flag ? - 1. : 1.) * x;
                    else if (op == AND)
                        A[i + j] = x + (flag ? - 1. : 1.) * y,
                        A[i + j + len] = y;
                    else
                        A[i + j] = (x + y) / (flag ? 2. : 1.),
                        A[i + j + len] = (x - y) / (flag ? 2. : 1.);
                }
        }
    }
}
using namespace FastWT;
double f[N];
int cnt[N];
signed main()
{
    int siz;
    scanf("%d", &siz);
    siz = 1 << siz;
    for (re int i = 0; i < siz; ++i) scanf("%lf", &f[i]);
    for (re int i = 1; i < siz; ++i) cnt[i] = cnt[i >> 1] + (i & 1);
    FWT<OR>(f, siz, 0);
    for (re int i = 0; i < siz - 1; ++i) if (1. - f[i] < eps) return puts("INF"), 0;
    double ans = 0;
    const int X = siz - 1;
    for (re int i = 1; i < siz; ++i) ans = ans + (cnt[i] + 1 & 1 ? -1.0 : 1.0) / (1.0 - f[i ^ X]);
    printf("%.10lf", ans);
    return 0;
}

标签:max,min,int,选到,HAOI2015,按位,siz,define
来源: https://www.cnblogs.com/After-glow/p/15836744.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有