比赛链接

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. 运筹学 | 退化的最优解 vs 无穷多最优解?

    退化的最优解: 单纯形表的基可行解中,出现等于零的基变量.或者,按最小比值来确定出基向量时,存在两个以上相同最小比值. 出现的原因:模型中存在多余的约束. 无穷多最优解: 单纯形表中,按最大检验数 σ ...

  2. 通过设置 Chrome 解决开发调用跨域问题

    转载请注明出处: 项目采用的是前后端分离的方式,前端本地访问方式是 localhost:8080,访问本地后台服务时,通过 localhost:9000 进行访问 本地后端服务.在本地通过chrome ...

  3. [转帖]KingbaseES wal(xlog) 日志清理故障恢复案例

    https://www.cnblogs.com/kingbase/p/16266365.html 案例说明:在通过sys_archivecleanup工具手工清理wal日志时,在control文件中查 ...

  4. 【转帖】Linux 系统双网卡绑定 bond的7种模式

    第一种模式:mod=0 ,即:(balance-rr) Round-robin policy(平衡抡循环策略)第二种模式:mod=1,即: (active-backup) Active-backup ...

  5. 【转帖】Linux性能优化(十六)——中断绑定

    一.中断绑定简介 1.中断简介 计算机中,中断是一种电信号,由硬件产生并直接送到中断控制器上,再由中断控制器向CPU发送中断信号,CPU检测到信号后,中断当前工作转而处理中断信号.CPU会通知操作系统 ...

  6. [转帖]TaiShan v110 - Microarchitectures - HiSilicon

      https://en.wikichip.org/wiki/hisilicon/microarchitectures/taishan_v110 Edit Values TaiShan v110 µa ...

  7. [转帖][问题已处理]-kubernetes中2次不同的oom处理

    https://dandelioncloud.cn/article/details/1598699030236577793 起因: 同事反馈 服务挂了,kuboard上查看是服务挂掉了,livenes ...

  8. [转帖]Nginx四层负载均衡详解

    https://developer.aliyun.com/article/885599?spm=a2c6h.24874632.expert-profile.315.7c46cfe9h5DxWK 202 ...

  9. [专题]中立遭质疑,提价遭反对,ARM的生存难题怎么破?

    中立遭质疑,提价遭反对,ARM的生存难题怎么破? https://news.cnblogs.com/n/669715/ ARM税要提高.. RISC-V的机会? 文/黎文婕 来源:锌刻度(ID:znk ...

  10. element-plus 按需引入将英文组件修改为中文

    element-plus 默认是英文组件:如下图 将它设置为中文组件 app.vue文件 <template> <el-config-provider :locale="l ...