SMU Summer 2024 Contest Round 4
SMU Summer 2024 Contest Round 4
Made Up
题意
给你三个序列 \(A,B,C\) ,问你满足 \(A_i = B_{C_j}\) 的 \((i,j)\) 对有多少。
思路
由于 \(1\le A_i,B_i,C_i\le N\) ,所以可以统计 \(Cnt[A_i]\) 和 \(Cnt[B_{C_i}]\) 的个数,两者相乘累加即可。
代码
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n), b(n), c(n);
vector<i64> cnta(n + 1);
for (auto &i : a) {
cin >> i;
cnta[i] ++;
}
for (auto &i : b)
cin >> i;
vector<i64> cntb(n + 1);
for (auto &i : c) {
cin >> i;
cntb[b[--i]] ++;
}
i64 ans = 0;
for (int i = 1; i <= n; i ++) {
ans += cnta[i] * cntb[i];
}
cout << ans << '\n';
return 0;
}
H and V
题意
给你 \(H\times W\) 的只包含. 和#的矩阵, 你可以选择任意行任意列改成.,问你修改后使得矩阵中#的个数等于 k 的方案有多少种。
思路
因为 \(1\le H,W\le 6\),所以直接对边和列枚举改哪些行和列即可。
代码
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int h, w, k;
cin >> h >> w >> k;
vector<string> s(h);
for (auto &i : s)
cin >> i;
auto calc = [](vector<string> ss) {
int res = 0;
for (auto i : ss)
for (auto c : i)
res += (c == '#');
return res;
};
int ans = 0;
for (int i = 0; i < (1 << h); i ++) {
for (int j = 0; j < (1 << w); j ++) {
auto S = s;
for (int k = 0; k < h; k ++)
if ((i >> k) & 1)
S[k] = string(w, '.');
for (int k = 0; k < w; k ++)
if ((j >> k) & 1) {
for (int p = 0; p < h; p ++)
S[p][k] = '.';
}
if (calc(S) == k)
ans ++;
}
}
cout << ans << '\n';
return 0;
}
Moving Piece
题意
给你 n 个点,然后每个点 可以到达其他第 \(P_i\) 个点,到达下个点后可以获得对应的 \(C_i\) 分数,你可以选择某个点为起始点走 \(K\) 步,起始点的分数不计,问你最大能获得多少分。
思路
因为每个点只有一个方向,所以将它们抽象成图以后就是多个环,而你需要在这些环上找一个环走 \(K\) 步。
当走的步数大于环上的点数时,直接计算一下会经过多少次这个环,乘以环的总分数即可。
代码
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
vector<int> p(n + 1);
for (int i = 1; i <= n; i ++)
cin >> p[i];
vector<int> C(n + 1);
for (int i = 1; i <= n; i ++)
cin >> C[i];
i64 ans = INT_MIN;
for (int i = 1; i <= n; i ++) {
i64 to = i, sum = 0;
vector<i64> path;
while (true) {
to = p[to];
sum += C[to];
path.push_back(sum);
if (to == i) break;
}
const int dis = path.size();
for (int j = 0; j < dis && j < k; j ++) {
int CircleNum = (k - 1 - j) / dis;
ans = max(ans, path[j]);
if(CircleNum > 0)
ans = max(ans, path[j] + CircleNum * sum);
}
}
cout << ans << '\n';
return 0;
}
Sum of Divisors
题意
设 \(f(X)\) 为 \(X\) 的所有因子数,求 \(\sum_{K=1}^NK\times f(K)\)。
思路
考虑一个数产生的贡献。
对于一个数,它只会在它的倍数中产生贡献,例如,2 只会在 \(2,4,6,8,10\dots\) 中产生贡献,而在上界为 \(N\) 的情况下只会有 \(\frac{N}{i}\) 个 \(i\) 的倍数,而对于 2 而言,它在 2 中产生的贡献为 2,在4 中的产生的贡献为 4,在 6 中产生的贡献为 6,\(\dots\),其他数同理,观察可得一个数产生的贡献为 \(i + 2i+3i+4i+\dots\),没错,这就是一个首项为 \(i\) ,公差为 \(i\),项数为 \(\frac{N}{i}\),末项为 \(\lfloor\frac{N}{i}\rfloor\times i\) 的等差数列,所以从 1 到 n 累加求和即可。
\]
代码
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
i64 ans = 0;
for(int i = 1;i <= n;i ++){
i64 d = i, a1 = i, len = n / i, an = d * len;
ans += len * (a1 + an) / 2;
}
cout << ans << '\n';
return 0;
}
Red and Green Apples
题意
给你三个序列 \(A,B,C\),\(C\) 序列中的任何数可以替换 \(A,B\) 中的任何数,你要选出 A 中 X 个,B 中 Y 个,求它们的和最大。
思路
将 A,B 排序后取前 X 个和前 Y 个放入 C 中,再将 C 排序,取出前 X+Y 个即可。
代码
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int x, y, a, b, c;
cin >> x >> y >> a >> b >> c;
vector<int> A(a), B(b), C(c);
for (auto &i : A)
cin >> i;
for (auto &i : B)
cin >> i;
for (auto &i : C)
cin >> i;
sort(A.begin(), A.end(), greater<>());
sort(B.begin(), B.end(), greater<>());
for(int i = 0;i < x;i ++)
C.push_back(A[i]);
for(int i = 0;i < y;i ++)
C.push_back(B[i]);
sort(C.begin(),C.end(),greater<>());
i64 ans = 0;
for(int i = 0;i < x + y;i ++)
ans += C[i];
cout << ans << '\n';
return 0;
}
Rem of Sum is Num
题意
给你序列 A,求 A 中连续子序列之和模 K 后等于该子序列中元素数量的连续子序列数量。
思路
转化题意,即求:
\]
复杂度\(O(n^3)\),显然超时。
考虑优化,前缀和优化即:
\]
\]
\]
即当满足以上条件相等时,说明 \((l-1,r]\) 是一段满足要求的连续子序列。
因为这里 r 从 1 开始时,l - 1 会等于 0 ,所以需要我们将 0 的方案数初始化为 1 。
至此,这道题就变成了求区间长度最大为 k 的 满足以上条件的方案数,在模 k 后其区间元素数量最多为 k ,否则就不满足条件,超过区间长度需减掉。
代码
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
i64 n, k;
cin >> n >> k;
vector<i64> a(n + 1), pre(n + 1);
for (int i = 1; i <= n; i ++) {
cin >> a[i];
pre[i] = pre[i - 1] + a[i];
}
for (int i = 1; i <= n; i ++) {
pre[i] = (pre[i] - i) % k;
}
i64 ans = 0;
int len = min(k-1, n);
map<i64, i64> mp;
mp[0] = 1;
for (int i = 1; i <= n; i ++) {
if (i > len) mp[pre[i - k]]--;
ans += mp[pre[i]];
mp[pre[i]] ++;
}
cout << ans << '\n';
return 0;
}
Keep Connect
题意

给定 $ n, p $,存在如图的 $ 2 \times n $ 的网格图,显然初始共有 $ 2n $ 个顶点和 $ 3n - 2 $ 条边,分别求删除 $ i \in [1, n - 1] $ 条边后仍使图连通的删边方案数,对 $ p $ 取模。
思路
将上下的两个点看成一列,考虑 dp。
设 \(dp_{i,j,0/1}\) 为前 i 列中删掉 j 条边是否连通的方案数。
首先假设第 i 列连通:
那么会有四种情况使得第 i+1 列连通:
前三种:



得出转移方程为 \(dp_{i+1,j+1,1} += dp_{i,j,1}\times 3\)第四种:

得出转移方程为 \(dp_{i+1,j,1}+=dp_{i,j,1}\)
会有两种情况使得第 i+1 列无法连通:


得出转移方程为 \(dp_{i+1,j+2,0}+=dp_{i,j,1}\times 2\)
假设第 i 列不连通:
使得第 i+1 列连通:

得出转移方程为 \(dp_{i+1,j,1}+=dp_{i,j,0}\)
使得第 i+1 列不连通:

得出转移方程为 \(dp_{i+1,j+1,0}+=dp_{i,j,0}\)
另外还有些减去三边的情况,但是那种情况产生后后面都不可能再连通,对答案无贡献。
代码
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
const int N = 3e3 + 10;
i64 dp[N][N][2];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
i64 n, p;
cin >> n >> p;
dp[1][0][1] = dp[1][1][0] = 1;
for (int i = 1; i <= n; i ++) {
for (int j = 0; j < n; j ++) {
dp[i + 1][j + 1][1] = (dp[i + 1][j + 1][1] + dp[i][j][1] * 3) % p;
dp[i + 1][j][1] = (dp[i + 1][j][1] + dp[i][j][1]) % p;
dp[i + 1][j + 2][0] = (dp[i + 1][j + 2][0] + dp[i][j][1] * 2) % p;
dp[i + 1][j][1] = (dp[i + 1][j][1] + dp[i][j][0]) % p;
dp[i + 1][j + 1][0] = (dp[i + 1][j + 1][0] + dp[i][j][0]) % p;
}
}
for (int i = 1; i < n; i ++)
cout << dp[n][i][1] << " \n"[i == n - 1];
return 0;
}
SMU Summer 2024 Contest Round 4的更多相关文章
- 2015 Astar Contest - Round 3 题解
1001 数长方形 题目大意 平面内有N条平行于坐标轴的线段,且不会在端点处相交 问共形成多少个矩形 算法思路 枚举4条线段的全部组合.分别作为矩形四条边.推断是否合法 时间复杂度: O(N4) 代码 ...
- Contest Round #451 (Div. 2)F/Problemset 898F Restoring the Expression
题意: 有一个a+b=c的等式,去掉两个符号,把三个数连在一起得到一个数 给出这个数,要求还原等式,length <= 1e6 三个数不能含有前导0,保证有解 解法: 铁头过题法,分类然后各种判 ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Sending messages to non-windowed applications -- AllocateHWnd, DeallocateHWnd
http://delphi.about.com/od/windowsshellapi/l/aa093003a.htm Page 1: How Delphi dispatches messages in ...
- Codeforces 240 F. TorCoder
F. TorCoder time limit per test 3 seconds memory limit per test 256 megabytes input input.txt output ...
- cf499B-Lecture 【map】
http://codeforces.com/problemset/problem/499/B B. Lecture You have a new professor of graph theo ...
- Codeforces 240F. TorCoder 线段树
线段树统计和维护某一区间内的字母个数.. . . F. TorCoder time limit per test 3 seconds memory limit per test 256 megabyt ...
- 物联网学生科协第三届H-star现场编程比赛
问题 A: 剪纸片 时间限制: 1 Sec 内存限制: 128 MB 题目描写叙述 这是一道简单的题目,假如你身边有一张纸.一把剪刀.在H-star的比赛现场,你会这么做: 1. 将这张纸剪成两片(平 ...
- [cf contest 893(edu round 33)] F - Subtree Minimum Query
[cf contest 893(edu round 33)] F - Subtree Minimum Query time limit per test 6 seconds memory limit ...
- 水题 Codeforces Round #307 (Div. 2) A. GukiZ and Contest
题目传送门 /* 水题:开个结构体,rk记录排名,相同的值有相同的排名 */ #include <cstdio> #include <cstring> #include < ...
随机推荐
- Mybatis、Mybatis Generator、Mybatis-Plus、Mybatis Plus Generator
1.介绍 Mybatis Mybatis 是操作数据库的框架:提供一种Mapper类,支持用Java代码对数据库进行增删改查. 缺点:需要先在xml中写好SQL语句: Mybatis Generato ...
- 【论文阅读】Exploring the Limitations of Behavior Cloning for Autonomous Driving
Column: January 16, 2022 11:11 PM Last edited time: January 21, 2022 12:23 PM Sensor/组织: 1 RGB Statu ...
- SpringBoot+mail 轻松实现各类邮件自动推送
一.简介 在实际的项目开发过程中,经常需要用到邮件通知功能.例如,通过邮箱注册,邮箱找回密码,邮箱推送报表等等,实际的应用场景非常的多. 早期的时候,为了能实现邮件的自动发送功能,通常会使用 Java ...
- OpenBMB × Hugging Face × THUNLP,联袂献上经典大模型课
这个夏天,THUNLP 携手 Hugging Face 和 OpenBMB,推出 大模型公开课第二季.在大模型公开课第二季中,将有全球知名开源社区 OpenBMB X Hugging Face 梦幻联 ...
- [oeasy]python0135_python_语义分析_ast_抽象语法树_abstract_syntax_tree
语义分析_抽象语法树_反汇编 回忆 上次回顾了一下历史 python 是如何从无到有的 看到 Guido 长期的坚持和努力 添加图片注释,不超过 140 字(可选) python究竟是 ...
- oeasy教您玩转vim - 6 - # 保存修改
另存与保存 回忆上节课内容 我们上次进入了插入模式 从正常模式,按<kbd>i</kbd>,进插入模式 从插入模式,按<kbd>ctrl</kbd>+& ...
- [oeasy]python0024_ 输出时间_time_模块_module_函数_function
输出时间 回忆上次内容 print函数 有个默认的 end参数 end参数 的值可以是任意字符串 end参数 的值会输出到结尾位置 end参数 的默认值是 ...
- 题解:B3646 数列前缀和 3
分析 板子题,线段树维护矩阵区间积,除了难写没什么思维难度. 所以直接放代码吧. Code #include<bits/stdc++.h> #define int long long us ...
- 基于Hive的大数据分析系统
1.概述 在构建大数据分析系统的过程中,我们面对着海量.多源的数据挑战,如何有效地解决这些零散数据的分析问题一直是大数据领域研究的核心关注点.大数据分析处理平台作为应对这一挑战的利器,致力于整合当前主 ...
- ansible 一键部署openstack (双节点)
1.三台虚拟机设置 ansible 内存 2GB 处理器 4 硬盘 40GB 光盘iso centos1804 网络适配器 仅主机模式 显示器 自动检测 controller 内存 5.3GB 处理器 ...