惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
The Cloudflare Blog
L
LangChain Blog
博客园 - 司徒正美
G
Google Developers Blog
博客园 - 【当耐特】
GbyAI
GbyAI
月光博客
月光博客
人人都是产品经理
人人都是产品经理
D
DataBreaches.Net
大猫的无限游戏
大猫的无限游戏
A
About on SuperTechFans
Microsoft Azure Blog
Microsoft Azure Blog
V
Visual Studio Blog
D
Docker
MongoDB | Blog
MongoDB | Blog
Vercel News
Vercel News
Stack Overflow Blog
Stack Overflow Blog
Jina AI
Jina AI
博客园 - 聂微东

某岛

AtCoder Beginner Contest 409 Luogu P5325. 【模板】Min_25 筛 UOJ #188. 【UR #13】Sanrd AtCoder Beginner Contest 371 AtCoder Beginner Contest 369 RPGMaker 2k3 百科 OneShot 的考古 2024“开创拓芯”游戏创享节的相关记录 CJ 回来后的戒断反应 Luogu P10221. [省选联考 2024] 重塑时光 Luogu P5308 [COCI2018-2019#4] Akvizna wqs 二分 歌唱王国 Lean 相关 BZOJ 3153. Sone1 The 2023 ICPC World Finals Luxor 新巴别塔 Sora 的想象与思考 Facebook Hacker Cup 2023 Round 1 AtCoder Beginner Contest 322 LLaMA 2 相关 HuggingFace AI Game Jam ACL 2023 Trans 相关… Luogu P2053. [SCOI2007] 修车 Luogu P1973. [NOI2011] NOI 嘉年华 Luogu P1933. [NOI2010] 旅行路线 Luogu P1954. [NOI2010] 航空管制 Luogu P2048. [NOI2010] 超级钢琴 Luogu P2046. [NOI2010] 海拔
AtCoder Beginner Contest 297
2023-04-25 · via 某岛

Problem D. Count Subtractions

想到前几天 uoj 出的那个 gcd 数论题。。。

Problem E. Kth Takoyaki Set

Humble Number?
结果居然暴力就过了。。。

#include <lastweapon/io>
using namespace lastweapon;
const int N = int(1e2) + 9;

int n, k, a[N];

int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#endif
    
    RD(n, k); REP(i, n) RD(a[i]);
    set<LL> s; s.insert(0);

    DO(k) {
        LL x = *s.begin(); s.erase(s.begin());
        REP(i, n) {
            LL t = x + a[i];
            s.insert(t);
        }
    }
    cout << *s.begin() << endl;
}

Problem F. Minimum Bounding Box 2

容斥原理。

一种做法是直接枚举 Bounding Box,然后容斥掉至少小一圈的情况。
这种做法要对四个边界的 2^4 种存在情况分别进行容斥。

#include <lastweapon/io>
#include <lastweapon/bitwise>
#include <lastweapon/number>
using namespace lastweapon;
const int N = int(1e6) + 9;
Int Fact[N], iFact[N];
int n, m, k;

Int Binom(int n, int m) {
    if (m < 0 || m > n) return 0;
    return Fact[n] * iFact[m] * iFact[n-m];
}

Int f(int n, int m) {
    Int z = 0; REP(s, _1(4)) {
        int a = n - _1(s, 0) - _1(s, 1); if (a <= 0) continue;
        int b = m - _1(s, 2) - _1(s, 3); if (b <= 0) continue;
        Int d = Binom(a*b, k);
        if (count_bits(s) & 1) z -= d; else z += d;
    }
    return z;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif

    MOD = 998244353;

    RD(n, m, k); Fact[0] = 1; REP_1(i, n*m) Fact[i] = Fact[i-1] * i; iFact[n*m] = _I(Fact[n*m]);
    DWN_1(i, n*m, 1) iFact[i-1] = iFact[i] * i;

    Int z = 0; REP_1(i, n) REP_1(j, m) z += f(i, j)*i*j*(n+1-i)*(m+1-j);
    z /= Binom(n*m, k);
    cout << z << endl;
}

更好的做法是利用期望的线性性。。单独考察每个格子。。统计它对答案的影响。。。
只要容斥掉四个角即可。

#include <lastweapon/io>
#include <lastweapon/bitwise>
#include <lastweapon/number>
using namespace lastweapon;
const int N = int(1e6) + 9;
Int Fact[N], iFact[N];
int n, m, k;

Int Binom(int n, int m) {
    if (m < 0 || m > n) return 0;
    return Fact[n] * iFact[m] * iFact[n-m];
}

Int f(int x, int y) {
    Int z = Binom(n*m, k);
    z -= Binom((x-1)*m, k) + Binom((n-x)*m, k) + Binom(n*(y-1), k) + Binom(n*(m-y), k);
    z += Binom((x-1)*(y-1), k) + Binom((x-1)*(m-y), k) + Binom((n-x)*(y-1), k) + Binom((n-x)*(m-y), k);
    return z;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif

    MOD = 998244353;

    RD(n, m, k); Fact[0] = 1; REP_1(i, n*m) Fact[i] = Fact[i-1] * i; iFact[n*m] = _I(Fact[n*m]);
    DWN_1(i, n*m, 1) iFact[i-1] = iFact[i] * i;

    Int z = 0; REP_1(i, n) REP_1(j, m) z += f(i, j);
    z /= Binom(n*m, k);
    cout << z << endl;
}

Posted by xiaodao
Category: 日常