比赛链接

G

题解

知识点:思维。

\(lds(p)\) 表示最小上升子序列分划数 (Dilworth 定理)

\(lis(p)\cdot lds(p) \geq n \Rightarrow max \{lds(p), lis(p)\} \geq \lceil \sqrt n \rceil\)

因此将排列构造多个长度为 \(\lceil \sqrt n \rceil\) 递增串,并且递增串的最大值一定递减,形如 789456123 即可。

时间复杂度 \(O(n)\)

空间复杂度 \(O(1)\)

代码

#include <bits/stdc++.h>
#define ll long long using namespace std; bool solve() {
int n;
cin >> n;
int sn = ceil(sqrt(n));
for (int i = 1;i <= n;i += sn) {
for (int j = min(i + sn - 1, n);j >= i;j--)
cout << j << ' ';
}
cout << '\n';
return true;
} int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << -1 << '\n';
}
return 0;
}

J

题解

方法一

知识点:线性回归。

显然运用线性回归公式:

\[\begin{aligned}
y = Ax + B \Rightarrow
\left\{
\begin{array}{l}
A =& \dfrac{\sum_{i = 1}^n x_iy_i - n\bar x \bar y}{\sum_{i = 1}^n x_i^2 - n\bar x^2} \\
B =& \bar y - A\bar x \\
\end{array}
\right.
\end{aligned}
\]

注意精度。

时间复杂度 \(O(tn)\)

空间复杂度 \(O(n)\)

方法二

知识点:三分。

如果不知道线性回归,可以运用三分斜率 \(A\) ,已知过 \((\bar x,\bar y)\) 求 \(B\) ,同样注意精度。

时间复杂度 \(O(tn \log n)\)

空间复杂度 \(O(n)\)

代码

方法一

#include <bits/stdc++.h>
#include <cstdio>
#include <cctype>
#define ll long long using namespace std; namespace GTI {
char gc(void) {
const int S = 1 << 16;
static char buf[S], *s = buf, *t = buf;
if (s == t) t = buf + fread(s = buf, 1, S, stdin);
if (s == t) return EOF;
return *s++;
}
int gti(void) {
int a = 0, b = 1, c = gc();
for (; !isdigit(c); c = gc()) b ^= (c == '-');
for (; isdigit(c); c = gc()) a = a * 10 + c - '0';
return b ? a : -a;
}
}
using GTI::gti; int a[100007]; bool solve() {
int n = gti();
double xavg = (1 + n) / 2.0, yavg = 0;
ll Au = 0, Av = 0;
for (int i = 1;i <= n;i++) {
a[i] = gti();
yavg += a[i];
Au += 1LL * i * a[i];
Av += 1LL * i * i;
}
yavg /= n;
double A = (Au - n * xavg * yavg) / (Av - n * xavg * xavg);
double B = yavg - A * xavg;
double ans = 0;
for (int i = 1;i <= n;i++) ans += (A * i + B - a[i]) * (A * i + B - a[i]);
cout << fixed << setprecision(9) << ans << '\n';
return true;
} int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
t = gti();
while (t--) {
if (!solve()) cout << -1 << '\n';
}
return 0;
}

方法二

没写

K

题解

知识点:计数dp。

\(dp[i][j][k]\) 表示为 \(B\) 放了 \(i\) 个括号,\(B\) 与 \(A\) 的lcs为 \(j\) ,还有 \(k\) 个未匹配的左括号。

转移方程为:

int t = j + (s[j + 1] == '(');
dp[i + 1][t][k + 1] = (dp[i][j][k] + dp[i + 1][t][k + 1]) % mod; t = j + (s[j + 1] == ')');
if (k) dp[i + 1][t][k - 1] = (dp[i][j][k] + dp[i + 1][t][k - 1]) % mod;

上面是下一个位置放左括号的情况,下面是下一个位置放右括号的情况。

但是,通常转移方程都是当前状态是目标状态,这里是当前状态 \(dp[i][j][k]\) 是上一次状态,而目标状态并非当前状态。原因是如果知道当前状态,是找不到上一次状态的,因为不知道当前括号是不是与lcs对应的括号,因此转换递推方式,遍历已知推未知,而非遍历未知找已知推。

时间复杂度 \(O(tm^2n)\)

空间复杂度 \(O(m^2n)\)

代码

#include <bits/stdc++.h>
#define ll long long using namespace std; const int mod = 1e9 + 7;
int dp[207][207][207]; bool solve() {
memset(dp, 0, sizeof(dp));
int n, m;
cin >> n >> m;
string s;
cin >> s;
s = '?' + s + '?';
dp[0][0][0] = 1;
for (int i = 0;i <= m - 1;i++) {
for (int j = 0;j <= min(i, n);j++) {
for (int k = 0;k <= i;k++) {
int t = j + (s[j + 1] == '(');
dp[i + 1][t][k + 1] = (dp[i][j][k] + dp[i + 1][t][k + 1]) % mod;
t = j + (s[j + 1] == ')');
if (k) dp[i + 1][t][k - 1] = (dp[i][j][k] + dp[i + 1][t][k - 1]) % mod;
}
}
}
cout << dp[m][n][0] << '\n';
return true;
} int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << -1 << '\n';
}
return 0;
}

蔚来杯2022牛客暑期多校训练营2 GJK的更多相关文章

  1. 蔚来杯2022牛客暑期多校训练营5 ABCDFGHK

    比赛链接 A 题解 知识点:图论,dp. 暴力建图,连接所有点的双向通路,除了原点是单向的,并且把路径长度作为权值. 随后,从原点出发(\(f[0] = 0\),其他点负无穷,保证从原点出发),按照权 ...

  2. 蔚来杯2022牛客暑期多校训练营6 ABGJM

    比赛链接 A 题解 知识点:数学,构造. 题目要求构造一个长为 \(m\) 的序列 \(c\) ,\(m\) 自选,使得 \(c\) 的无限循环序列 \(b\) 中任意连续 \(a_i\) 个数中都存 ...

  3. 蔚来杯2022牛客暑期多校训练营7 CFGJ

    比赛链接 C 题解 方法一 知识点:思维. 先统计没有出现的数,每个都可以随便放,所以作为补位用的. 将原数组左移一位作为预定的答案数组,然后开始检查.如果和原数组一样,则用补位数字填充,如果不一样就 ...

  4. "蔚来杯"2022牛客暑期多校训练营9 G Magic Spells【马拉车+哈希】

    四川今天又上热搜了,继南部疫情的未雨绸缪后,龙槽沟是真的倾盆大雨了.我没有兴趣虚伪矫情地对罹难的游人表达同情,因为人与人互不相通徒增谈资:我也没有兴趣居高临下地对擅闯的愚人表达不屑,因为你我皆为乌合之 ...

  5. "蔚来杯"2022牛客暑期多校训练营1 C.Grab the Seat!

    C.Grab the Seat! 题目链接 https://ac.nowcoder.com/acm/contest/33186/C 题目大意 1.二维平面中,(0,1) - (0,m)为屏幕 2.有n ...

  6. 2019牛客暑期多校训练营(第五场)G - subsequeue 1 (一题我真的不会的题)

    layout: post title: 2019牛客暑期多校训练营(第五场)G - subsequeue 1 (一题我真的不会的题) author: "luowentaoaa" c ...

  7. 2021牛客暑期多校训练营3 J 思维

    传送门 J-Counting Triangles_2021牛客暑期多校训练营3 (nowcoder.com) 题目 Goodeat finds an undirected complete graph ...

  8. B-xor_2019牛客暑期多校训练营(第四场)

    题意 给出n个数组(每组数个数不定),m个询问 l, r, x 序号在区间\([l,r]\)的每个数组是否都可以取出任意个数异或出x 题解 判断一个数组能否异或出x,是简单的线性基问题 判断多个线性基 ...

  9. 2019牛客暑期多校训练营(第九场)A:Power of Fibonacci(斐波拉契幂次和)

    题意:求Σfi^m%p. zoj上p是1e9+7,牛客是1e9:  对于这两个,分别有不同的做法. 前者利用公式,公式里面有sqrt(5),我们只需要二次剩余求即可.     后者mod=1e9,5才 ...

  10. 2019牛客暑期多校训练营(第一场)A题【单调栈】(补题)

    链接:https://ac.nowcoder.com/acm/contest/881/A来源:牛客网 题目描述 Two arrays u and v each with m distinct elem ...

随机推荐

  1. spring cloud gateway在使用 zookeeper 注册中心时,配置https 进行服务转发

    本文为博主原创,转载请注明出处: 在spring cloud gateway 为 2.x 的版本的时候,可以通过引入 ribbon ,在进行过滤器 LoadBalancerClientFilter 进 ...

  2. c#.net 6 实现简单爬虫几行代码实现百度搜索

    使用selenium封装的简单使用工具包 Gitee:SeleniumUtil: Selenium简化工具包,包含三个主流浏览器的一些基本操作 (gitee.com) 第一步安装爬虫工具: 在程序包管 ...

  3. Angular系列教程之zone.js和NgZone

    .markdown-body { line-height: 1.75; font-weight: 400; font-size: 16px; overflow-x: hidden; color: rg ...

  4. CSS 动画 : 创建 3D 立方体

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. [转帖]一篇来自网络的关于“enqueue”events的简短参考

    https://www.cnblogs.com/lhdz_bj/p/8716701.html 仅供自己和各位同学参考: Enqueue Type Description enq: AD - alloc ...

  6. [粘贴]TiDB Lightning 断点续传

    https://www.bookstack.cn/read/tidb-6.1-zh/tidb-lightning-tidb-lightning-checkpoints.md 大量的数据导入一般耗时数小 ...

  7. [转帖]如何使用 minio 进行 BR 备份

    https://tidb.net/blog/ada69456#5.%20%E4%BD%BF%E7%94%A8%20minio%20%E8%BF%9B%E8%A1%8C%20BR%20%E5%A4%87 ...

  8. [转帖]华为FusionSphere虚拟化解决方案介绍

    https://huaweicloud.csdn.net/63566589d3efff3090b5d243.html?spm=1001.2101.3001.6650.2&utm_medium= ...

  9. [转帖]Jmeter跨线程组传参

    https://www.cnblogs.com/a00ium/p/10462576.html   我们知道,同一线程组中可以通过"正则表达式提取器"获取其中一个取样器的响应结果中的 ...

  10. [转帖]Linux—解压缩命令总结(tar/zip)

    https://www.jianshu.com/p/1ad5d852d13b 1 tar 1.2 tar介绍   tar命令是linux系统中对文件和目录解压缩命令.tar命令可以用于对后缀名为.ta ...