当前位置:网站首页>牛客2022 暑期多校4 D Jobs (Easy Version)(递推优化策略)
牛客2022 暑期多校4 D Jobs (Easy Version)(递推优化策略)
2022-08-02 07:20:00 【Morgannr】
题意:
给你 n 个公司的求职岗位,每个岗位有 三个要求:EQ、IQ、AQ,当你的这三项指标都 大于等于这个职位的标准时,这个公司就会邀请你入职。现在你有 q 个朋友,你要算出他们 分别会被多少个公司邀请,再根据 公司的数量 算出:
其中 ans 是第 i 个朋友收到公司邀请的数目,seed 是题目给我们的随机数种子。
思路:
这一题的主要问题就是,我们怎么能够知道 对于第 i 家公司,应聘者的三商是否能完全满足某个职位的需求。
先想 暴力怎么做:直接 for 循环用应聘者的三商对比当前公司的所有职位,来看 当前公司是否能邀请我们。
但这样的 时间复杂度是:n * q * mi,显然不行。
提示
1:查看 数据范围 我们发现 除了 职位数mi和 应聘者数q是常见的1e5、1e6级别。公司数n和三商的上限都是很小的,我们可以试着从这里想办法。提示
2:我们 并不用知道一个公司有多少职位是应聘者可以满足的,只要有 一个职位满足即可。
可以类比 二维前缀和,我们准备一个 三维数组,把 应聘公司的编号看成 i(新增的一维),把 应聘者 IQ 看成 j,EQ 看成 k,AQ 为 f[i][j][k],
f[i][j][k] 表示:在 应聘者的 IQ 范围 1 ~ j,EQ 范围 1 ~ k 的情况下,能够通过 第 i 家公司 招聘的 AQ 的最小值。
那么对于应聘者的 三商 abc 来说,只要 f[a][b] 小于等于 c,那么这个公司就是能够邀请我们的。
预处理完 f 数组之后,后续我们就可以在 O(1) 时间复杂度 内 判断这个公司是否能邀请应聘者。
注意:
- 因为有
n个公司,所以我们开的其实是一个15 * 410 * 410的 三维数组,实际做法和二维数组一样。 - 对于最终计算结果,用快速幂求出
seed的q - i次幂再乘上lastans,把n个朋友的运算结果加起来 即可。
#include <bits/stdc++.h>
#include <random>
using namespace std;
//#define map unordered_map
#define int long long
int seed;
uniform_int_distribution<> u(1, 400);
const int mod = 998244353;
int n, q;
const int N = 1e5 + 10, M = 410;
int f[15][M][M];
int ans;
int qmi(int a, int b)
{
int res = 1;
while (b)
{
if (b & 1) res = res * a % mod;
b >>= 1;
a = a * a % mod;
}
return res;
}
int solve(int iq, int eq, int aq) {
int cnt = 0;
for (int i = 1; i <= n; ++i) {
if (aq >= f[i][iq][eq]) ++cnt;
}
return cnt;
}
signed main()
{
cin >> n >> q;
memset(f, 0x3f, sizeof f);
for (int i = 1; i <= n; ++i) {
int m; scanf("%lld", &m);
for (int j = 1; j <= m; ++j) {
int a, b, c;
scanf("%lld%lld%lld", &a, &b, &c);
f[i][a][b] = min(f[i][a][b], c);
}
for (int j = 1; j <= 400; ++j) {
for (int k = 1; k <= 400; ++k) {
f[i][j][k] = min(min(f[i][j][k], f[i][j][k - 1]), f[i][j - 1][k]);
}
}
}
cin >> seed;
mt19937 rng(seed);
int lastans = 0;
for (int i = 1; i <= q; ++i) {
int IQ = (u(rng) ^ lastans) % 400 + 1; // The IQ of the i-th friend
int EQ = (u(rng) ^ lastans) % 400 + 1; // The EQ of the i-th friend
int AQ = (u(rng) ^ lastans) % 400 + 1; // The AQ of the i-th friend
lastans = solve(IQ, EQ, AQ); // The answer to the i-th friend
ans = (ans + lastans * qmi(seed, q - i)) % mod;
}
cout << ans << '\n';
return 0;
}
边栏推荐
- MySQL - slow query log
- 【CV】OpenVINO installation tutorial
- 停止精神内耗 每日分享
- RIP综合实验
- Please tell me, how to write Flink SQL and JDBC sink into mysql library and want to create an auto-incrementing primary key
- postgres 水平分表,自动创建分区,按时间分表
- LeetCode 2360. 图中的最长环
- Splunk Field Caculated Calculated Field
- Mysql报错2003 解决办法 Can‘t connect to MySQL server on ‘localhost‘ (10061)
- Splunk Field Caculated 计算字段
猜你喜欢

Kind of weird!Access the destination URL, the host can container but not

ROS file system and related commands

(2022 Niu Ke Duo School 5) D-Birds in the tree (tree DP)

论文理解:“Cross-Scale Residual Network: A GeneralFramework for Image Super-Resolution,Denoising, and “

playwright 爬虫使用

(2022 Nioke Duo School 5) C-Bit Transmission (Thinking)
![MySQL报错1055解决办法:[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains](/img/aa/ab58ec47bb96df803dbc6a8ff6dde3.png)
MySQL报错1055解决办法:[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains

HCIP第二天

LeetCode 2360. 图中的最长环

【CV】OpenVINO installation tutorial
随机推荐
ROS文件系统以及相关命令
Please tell me, how to write Flink SQL and JDBC sink into mysql library and want to create an auto-incrementing primary key
flutter解决键盘和输入框不适配问题
MySQL-数据库设计规范
MySQL-索引优化和查询优化
【CV】OpenVINO installation tutorial
MySQL-多版本并发控制
如何保护智能家居不受黑客攻击
Aided by training and learning by battle | The new version of the Offensive and Defense World Platform is officially launched!
MySQL-慢查询日志
Appium 滑动问题
HCIP 第四天
Go implements distributed locks
How to export multiple query results at once in SQL server 2014?
MySQL-Multiversion Concurrency Control
Understand Chisel language. 31. Chisel advanced communication state machine (3) - Ready-Valid interface: definition, timing and implementation in Chisel
Splunk Field Caculated 计算字段
flutter 参数传一个范型数据
The best interests of buying and selling stocks with handling fees [What is missing in the definition of DP status?]
gdalinfo: error while loading shared libraries: libgdal.so.30: cannot open shared object file: No su



