[AtcoderABC200E]Patisserie
[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\)
思路
也就是试填法
即枚举每一项元素 通过函数\(calc()\)计算该项排列或是数列的个数
根据排名快速确定每一位元素
现在的问题就是如何实现\(calc()\)
你可以通过打表 或是 硬推 得到一部分思路
根据第一个条件先确定第一位 (因为总和确定后面就好搞了
很容易可以发现
第一个条件就是再求\(
\begin{cases}
i + j + k = x \\
i \leq n \\
j \leq n \\
k \leq n \\
\end{cases}
\)的方案数
那么 随便 一算可以推出方案数
\begin{cases}
0,\quad x\in(-\infty,3)\cup(3n,\infty) \\
\frac{(x-1)(x-2)}{2},\quad x\in[3,3n]
\end{cases}
\]
或者说是
\begin{matrix}
x-1 \\
2 \\
\end{matrix}
\right)
\]
然后我们考虑一下加上限制
加上其中一项 就把它减去n算一下之前的g(x)
即\(g(x - n)\) 也就是
\begin{matrix}
x-n \\
2
\end{matrix}
\right)
\]
然后可以随意加其中一个 共有三种方案 系数为-3
任选其中两项、三项(好像用不到)同理
那么真正的方案书\(f(x)\)也就是
\]
补充:
这里还有一种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的更多相关文章
- 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 ...
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- CET4
Directions: For this part, you are allowed 30 minutes to write a short essay on the challenges of st ...
- KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解
KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...
随机推荐
- Compile Java Codes in Linux Shell instead of Ant Script
The following is frequently used ant script, compile some java source codes with a libary path, then ...
- spring-session-data-redis反序列化问题
springCloud项目,采用springSession,用户模块同时引入了spring-cloud-starter-security,在其他模块request.getSession()的时候抛了以 ...
- Git出错:“Please make sure you have the correct access rights and the repository exists.”
此问题是需要重置ssh密钥 解决步骤如下: 1.重置用户名和邮箱: 打开Git Bash 进入Git命令,输入以下命令 git config --global user.name "你的用户 ...
- 用kivy学习制作简易调色画板app
制作一款简易的调色画板,要用到的知识:页面布局.ToggleButton.ToggleButtonBehavior.get_color_from_hex(兼容十六进制编码颜色):功能上要可以选择颜色, ...
- gcc limits.h的bug定位看include_next和默认搜索路径
手编的交叉编译工具链经常报一堆宏未定义,例如下面是编译gtest的时候报_POSIX_PATH_MAX宏未定义,有时还会上报SSIZE_MAX等宏未定义: googletest/src/gtest-f ...
- 004 PCI Express体系结构(四)
一.PCI总线的中断机制 PCI总线使用INTA#.INTB#.INTC#和INTD#信号向处理器发出中断请求.这些中断请求信号为低电平有效,并与处理器的中断控制器连接.在PCI体系结构中,这些中断信 ...
- GitNote基于git的个人云笔记
优点 可以存储到git服务(如github,giteee)中的能看到历史版本的git记事本工具. git 是一个很棒的工具,GitNote 支持 git 的全部特性,并且不依赖本地 Git 环境. 你 ...
- shell 函数返回值与字典
shell的函数只能返回整数值,如果想让函数返回字符串可以在函数调用处为变量赋值. # 定义函数function test() { name=$1 echo "123213" } ...
- C++CLR类库封装Native类库并用C#调用 - 草稿
1.创建Native类库 新建项目->其他语言->Visual C++->Win32控制台应用程序->DLL 添加头文件 添加源文件 选择生成路 ...
- 【SOE】 ArcGIS Server对象扩展(SOE)开发注意事项
ArcGIS Server对象扩展(SOE)开发注意事项 1.SOE介绍 在ArcGIS 10.1中ArcGIS Server不在支持DCOM方式的连接,这也就意味着我们不能通过本地方式的连接使用A ...