[AtcoderABC200E]Patisserie

题面翻译

对于一个三元组\((i,j,k)\) 我们对它按如下要求进行升序排序:

  • 第一关键词 \(i + j + k\) 即三者总和

  • 第二关键词 \(i\)

  • 第三关键词 \(j\)

特别的 我们给出了\(n\)

对于任何一个三元组\((i,j,k)\ i\in[1,n], j\in[1,n], k\in[1,n]都存在\)

现在给出\(P\) 求出排名为P的三元组的具体元素 即\((i,j,k)\)

\(n \leq 10^6\ \ k \leq 10^3\)

思路

类似于Contor展开的排列计数方法

也就是试填法

即枚举每一项元素 通过函数\(calc()\)计算该项排列或是数列的个数

根据排名快速确定每一位元素

现在的问题就是如何实现\(calc()\)

你可以通过打表 或是 硬推 得到一部分思路

根据第一个条件先确定第一位 (因为总和确定后面就好搞了

很容易可以发现

第一个条件就是再求\(
\begin{cases}
i + j + k = x \\
i \leq n \\
j \leq n \\
k \leq n \\
\end{cases}
\)的方案数

那么 随便 一算可以推出方案数

\[g(x)=
\begin{cases}
0,\quad x\in(-\infty,3)\cup(3n,\infty) \\
\frac{(x-1)(x-2)}{2},\quad x\in[3,3n]
\end{cases}
\]

或者说是

\[\left(
\begin{matrix}
x-1 \\
2 \\
\end{matrix}
\right)
\]

然后我们考虑一下加上限制

加上其中一项 就把它减去n算一下之前的g(x)

即\(g(x - n)\) 也就是

\[\left(
\begin{matrix}
x-n \\
2
\end{matrix}
\right)
\]

然后可以随意加其中一个 共有三种方案 系数为-3

任选其中两项、三项(好像用不到)同理

那么真正的方案书\(f(x)\)也就是

\[f(x) = g(x) - 3g(x - n) + 3g(x - 2n) - g(x - 3n)
\]

补充:

这里还有一种DP写法 可能会好理解一些

本文就不再赘述 请读者自行思考或查阅

总结

这道题放在定位为普及模拟赛T2令人着实很吃惊

主要是时间较紧也就成了选手实力的分水岭

要看能不能往组合数的角度(插板法 也许吧)去想了

俺比赛的时候推出第一个式子以为是高阶等差数列 就开始没推出来

还是经验太少了 毕竟OI的数学题还是相对挺少的

Code

说实话真的短 就是思路挺妙的

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring> using namespace std; #define int long long int read(int x = 0, bool f = false, char ch = getchar()) {
for (; !isdigit(ch); ch = getchar()) f |= (ch == '-');
for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
return f ? ~x + 1 : x;
} int g(int x) {return x <= 2? 0 : ((x - 1) * (x - 2)) / 2;} int f(int x, int y) {return g(x) - 3 * g(x - y) + 3 * g(x - 2 * y) - g(x - 3 * y);} int n, k; signed main() {
// freopen("cake.in", "r", stdin);
// freopen("cake.out", "w", stdout);
n = read(), k = read();
for (int i = 3; i <= 3 * n; ++i) {
if (k <= f(i,n)) {
for (int j = 1; j <= n; ++j) {
int mn = max(1ll, i - j - n), mx = min(n, i - j - 1ll);
if (mx < mn) continue;
if (k <= mx - mn + 1)
return printf("%lld %lld %lld\n", j, mn + k - 1, i - j - mn - k + 1), 0;
k -= mx - mn + 1;
}
} else k -= f(i,n);
}
}

[AtcoderABC200E]Patisserie的更多相关文章

  1. The 10 best sweet treats in Singapore

    Every time I walk out of Changi airport's air-conditioning into the humid outdoors, there's a sweet ...

  2. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  3. CET4

    Directions: For this part, you are allowed 30 minutes to write a short essay on the challenges of st ...

  4. KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解

    KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...

随机推荐

  1. MapReduce框架原理-InputFormat数据输入

    InputFormat简介 InputFormat:管控MR程序文件输入到Mapper阶段,主要做两项操作:怎么去切片?怎么将切片数据转换成键值对数据. InputFormat是一个抽象类,没有实现怎 ...

  2. CentOS文件目录类语法

    目录 一.目录查看切换类 1. pwd 显示当前工作目录的绝对路径 2. ls 列出目录的内容 二.文件与目录创建删除类 1. mkdir 创建一个新目录 2. touch 创建空文件 3. rmdi ...

  3. Logback 快速入门 / 使用详解

    官方文档: http://logback.qos.ch/manual/index.html 一.简介 Java 开源日志框架,以继承改善 log4j 为目的而生,是 log4j 创始人 Ceki Gü ...

  4. Using Evernote with Wine on Mint

    Install Evernote Install Evernote in Wine: wine Evernote_xxx.exe; Backup Evernote Database File Loca ...

  5. 21JavaScript笔记(1)

    JavaScript 基于对象和事件驱动 简单描述性语言 函数优先 解释型(即时编译型) 具有安全性的脚本语言 1.js组成 核心语法(ECMAScript):开放的.标准的脚本语言规范,主要包含了语 ...

  6. 那些shellcode免杀总结

    首发先知: https://xz.aliyun.com/t/7170 自己还是想把一些shellcode免杀的技巧通过白话文.傻瓜式的文章把技巧讲清楚.希望更多和我一样web狗也能动手做到免杀的实现. ...

  7. 【阿菜Writeup】Security Innovation Smart Contract CTF

    赛题地址:https://blockchain-ctf.securityinnovation.com/#/dashboard Donation 源码解析 我们只需要用外部账户调用 withdrawDo ...

  8. 使用VSCode创建第一个VUE项目

    vue init webpack vue_test回车,然后输入工程名称vue_test vue:Missing space before value for key 'components' 原因是 ...

  9. pyspark默认使用python2-----更改

    默认使用的竟然是2.7好烦如何解决呢 配置环境变量就行了 vi ~/.bashrc 添加一句话 export PATH=/home/hadoop/app/python3/bin:$PATH 保存退出  ...

  10. Python也可以拥有延迟函数

    延迟函数defer 我们知道在Golang中有一个关键字defer,用它来声明在函数调用前,会让函数*延迟**到外部函数退出时再执行,注意,这里的退出含义:函数return返回或者函数panic退出 ...