COCI 2024/2025 #3
T1 P11474 [COCI 2024/2025 #3] 公交车 / Autobus
愤怒,从红升橙足以说明其恶心,考场上调了半小时才过。
这道题的车能够开 \(24\) 小时,并且他能从前一天开到第二天,由于它只能开 \(24\) 小时,所以说发车时间的时刻晚于或等于到达时间,说明他开了一天,由于这个,所以我们要处理 \(3\) 天的情况。
先把所有的时间段存下来,然后分别加 \(1440\) 和 \(2880\) 分钟,暴力匹配,时间复杂度 \(O(600^2) = O(1)\) (不是)。
//# pragma GCC optimize("Ofast")
# include <bits/stdc++.h>
# define fr front
# define il inline
# define fir first
# define sec second
# define vec vector
# define it iterator
# define pb push_back
# define lb lower_bound
# define ub upper_bound
# define all(x) x.begin(), x.end()
# define mem(a, b) memset(a, b, sizeof(a))
# define lc (t[p].l)
# define rc (t[p].r)
# define ls(x) (x << 1)
# define rs(x) (x << 1 | 1)
# define lson ls(p), l, mid
# define rson rs(p), mid + 1, r
# define sqr(x) ((x) * (x))
# define bpc __builtin_popcount
# define lowbit(x) ((x) & (-(x)))
# define geti(x, i) (((x) >> (i)) & 1)
# define set1(x, i) ((x) | (1 << (i)))
# define set0(x, i) ((x) & (~(1 << (i))))
# define debug1(x) cerr << #x << " = " << x << " "
# define debug2(x) cerr << #x << " = " << x << "\n"
# define bug cerr << "--------------------------\n"
# define each1(i, x) for(auto (i) : (x))
# define each2(i, x) for(auto (&i) : (x))
# define rep(i, a, b) for(int i = (a); i <= (b); ++ i)
# define pre(i, a, b) for(int i = (a); i >= (b); -- i)
# define G(i, h, u, ne) for(int i = h[(u)]; i; i = ne[i])
# define reps(i, a, b, c) for(int i = (a); i <= (b); i += (c))
# define pres(i, a, b, c) for(int i = (a); i >= (b); i -= (c))
using namespace std;
using DB = double;
using LL = long long;
using LDB = long double;
using PII = pair<int, int>;
using ULL = unsigned long long;
const int INF1 = 0x3f3f3f3f, INF2 = INT_MAX;
const LL INF3 = (LL)1e18, INF4 = 0x3f3f3f3f3f3f3f3f, INF5 = LLONG_MAX;
int n, ans;
vec<PII> tmp1, tmp2, v1, v2;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
ans = INF1;
char ch, s[114];
int h1, h2, m1, m2;
cin >> n;
rep(i, 1, n){
cin >> s + 1;
if(s[1] == 'Z'){
cin >> h1 >> ch >> ch;
m1 = (ch - '0') * 10;
cin >> ch;
m1 += ch - '0';
cin >> ch >> ch;
cin >> h2 >> ch >> ch;
m2 = (ch - '0') * 10;
cin >> ch;
m2 += ch - '0';
int t1 = h1 * 60 + m1;
int t2 = h2 * 60 + m2;
if(t1 > t2) tmp1.pb({t1, t2 + 1440});
else tmp1.pb({t1, t2});
}
else{
cin >> h1 >> ch >> ch;
m1 = (ch - '0') * 10;
cin >> ch;
m1 += ch - '0';
cin >> ch >> ch;
cin >> h2 >> ch >> ch;
m2 = (ch - '0') * 10;
cin >> ch;
m2 += ch - '0';
int t1 = h1 * 60 + m1;
int t2 = h2 * 60 + m2;
if(t1 > t2) tmp2.pb({t1, t2 + 1440});
else tmp2.pb({t1, t2});
}
}
each2(x, tmp1){
v1.pb(x);
v1.pb({x.fir + 1440, x.sec + 1440});
v1.pb({x.fir + 2880, x.sec + 2880});
}
each2(x, tmp2){
v2.pb(x);
v2.pb({x.fir + 1440, x.sec + 1440});
v2.pb({x.fir + 2880, x.sec + 2880});
}
each2(a, v1){
each2(b, v2){
if(a.sec >= b.fir) continue;
ans = min(ans, b.sec - a.fir + 1);
}
}
if(ans == INF1) cout << "NEMOGUCE";
else{
cout << ans / 60 << ":";
ans %= 60;
if(ans < 10) cout << "0";
cout << ans;
}
return 0;
}
T2 P11475 [COCI 2024/2025 #3] 红蓝牌 / Karte
考场上轻信了 @ma_niu_bi 的话,用 DP 做,实际上我没有按照 DP 想的时候,直接 \(5\) 分钟就秒了。
看到 \(1 \le N,M \le 21\),\(0 \le X,Y \le 30\),其实我就有想法了,\(\rm strength = w − X \times r − Y \times b\),如果说我们能够枚举哪些红牌需要选,对于每张蓝牌,选与不选就取决于他能与红牌组成好对的数量大不大于 \(Y\),因为 \(X \times r\) 已经确定了(枚举的)。时间复杂度 \(O(2^n \times m \times n)\) 改好能卡过。
//# pragma GCC optimize("Ofast")
# include <bits/stdc++.h>
# define int LL
# define fr front
# define il inline
# define fir first
# define sec second
# define vec vector
# define it iterator
# define pb push_back
# define lb lower_bound
# define ub upper_bound
# define all(x) x.begin(), x.end()
# define mem(a, b) memset(a, b, sizeof(a))
# define lc (t[p].l)
# define rc (t[p].r)
# define ls(x) (x << 1)
# define rs(x) (x << 1 | 1)
# define lson ls(p), l, mid
# define rson rs(p), mid + 1, r
# define sqr(x) ((x) * (x))
# define bpc __builtin_popcount
# define lowbit(x) ((x) & (-(x)))
# define geti(x, i) (((x) >> (i)) & 1)
# define set1(x, i) ((x) | (1 << (i)))
# define set0(x, i) ((x) & (~(1 << (i))))
# define debug1(x) cerr << #x << " = " << x << " "
# define debug2(x) cerr << #x << " = " << x << "\n"
# define bug cerr << "--------------------------\n"
# define each1(i, x) for(auto (i) : (x))
# define each2(i, x) for(auto (&i) : (x))
# define rep(i, a, b) for(int i = (a); i <= (b); ++ i)
# define pre(i, a, b) for(int i = (a); i >= (b); -- i)
# define G(i, h, u, ne) for(int i = h[(u)]; i; i = ne[i])
# define reps(i, a, b, c) for(int i = (a); i <= (b); i += (c))
# define pres(i, a, b, c) for(int i = (a); i >= (b); i -= (c))
using namespace std;
using DB = double;
using LL = long long;
using LDB = long double;
using PII = pair<int, int>;
using ULL = unsigned long long;
const int N = 25, X = 35;
const int INF1 = 0x3f3f3f3f, INF2 = INT_MAX;
const LL INF3 = (LL)1e18, INF4 = 0x3f3f3f3f3f3f3f3f, INF5 = LLONG_MAX;
int n, m, x, y, ans, val, cnt;
char ok[N][N];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> m >> x >> y;
rep(i, 1, n){
cin >> ok[i] + 1;
}
rep(s, 0, (1 << n) - 1){
val = bpc(s) * (-x);
rep(i, 1, m){
cnt = 0;
rep(j, 0, n - 1){
if(geti(s, j)) cnt += (ok[j + 1][i] - '0');
}
if(cnt - y > 0) val += cnt - y;
}
ans = max(ans, val);
}
cout << ans;
return 0;
}
T3 P11476 [COCI 2024/2025 #3] 涂矩阵 / Bojanje
手模样例可以隐隐约约的感觉到,如果一行/列的颜色全部为 \(1/2\),那么这一行/列就可以在最后填。但是我们发现全部为 \(1/2\) 的就那么多,剩下的咋办?我们可以把最后填的一行/列的颜色在脑海中置为 \(-1\),也就是两种颜色都可以。然后就可以一直推下去。我们维护每一行/列的 \(1/2\) 的个数,每次从新 \(O(n)\) 遍历,把个数为 \(n\) 在原数组 \(a\) 中置为 \(-1\)。如果没有找到那我们直接判断有无解,那就是原数组 \(a\) 是否只由 \(-1/0\) 构成,如果不是,无解(此时已经找不到填的了,当然无解),有解就倒着输出答案。时间复杂度应该是 \(O(n^2)\),反正是能过。
# include <bits/stdc++.h>
# define vec vector
# define pb push_back
# define rep(i, a, b) for(int i = (a); i <= (b); ++ i)
# define pre(i, a, b) for(int i = (a); i >= (b); -- i)
using namespace std;
const int N = 2e3 + 10;
int n;
int a[N][N], row[3][N], col[3][N];
bitset<N> visrow, viscol;
struct node{
int type, rowcol, c;
};
vec<node> ans;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n;
rep(i, 1, n){
rep(j, 1, n){
cin >> a[i][j];
}
}
rep(i, 1, n){
rep(j, 1, n){
row[1][i] += (a[i][j] == 1);
row[2][i] += (a[i][j] == 2);
}
}
rep(i, 1, n){
rep(j, 1, n){
col[1][i] += (a[j][i] == 1);
col[2][i] += (a[j][i] == 2);//初始化数组
}
}
while(1){
bool sol = false;
rep(c, 1, 2){
rep(i, 1, n){
if(row[c][i] == n && !visrow[i]){//前提是没填过
sol = true;
visrow[i] = true;
ans.pb({1, i, c});
rep(j, 1, n){
col[3 - c][j] ++;//相同颜色已经计算过,不能再次计算,所以3-c
a[i][j] = -1;//记得置为-1
}
}
}
}
rep(c, 1, 2){
rep(i, 1, n){
if(col[c][i] == n && !viscol[i]){
sol = true;
viscol[i] = true;
ans.pb({2, i, c});
rep(j, 1, n){
a[j][i] = -1;
row[3 - c][j] ++;
}
}
}
}
if(!sol){//没法填了
rep(i, 1, n){
rep(j, 1, n){
if(a[i][j] != 0 && a[i][j] != -1){//无解,你已经没法填了,当然是无解
cout << "-1";
return 0;
}
}
}
break;
}
}
cout << ans.size() << "\n";
while(!ans.empty()) cout << ans.back().type << " " << ans.back().rowcol << " " << ans.back().c << "\n", ans.pop_back();//倒着输出
return 0;
}
T4 P11477 [COCI 2024/2025 #3] 林卡树 / Stablo
这道题很唐,考场上我们机房都没有人开,以为是紫色的,后来发现我 \(10\) 分钟就能秒。
如果一个玩意带修,你可以先看它的不带修版本咋做,直接树形 DP:
void dfs(int u, int fa){
sum[u] = val[u];
each2(v, e[u]){
if(fa == v) continue;
dfs(v, u);
dp[u] += dp[v] + sum[v];
sum[u] += sum[v];
}
}
因为每次距离加 \(1\),所以说 DP 值就应该是子树 DP 和再加上子树的值和。
但是这玩意也不能说他是完全带修,因为每次操作都是在初始形态的树上操作。既然已经想到这一步,我们直接看操作。首先如果 \(x\) 是 \(y\) 的儿子,那直接输出 \(dp_y\)。否则我们看操作的影响,对于 \(dp_y\) 来说,由于 \(x\) 接在 \(z\) 上,那么需要先预处理跳 \(z\) 的倍增(不会可以学倍增 LCA),跳了以后,\(z\) 子树除 \(x\) 的子树全部深度加一,所以加 \(sum_z\) 再减去 \(sum_x\),而 \(x\) 多算了 \(deep_x - deep_y\) 次,减去 \((deep_x - deep_y) \times val_x\),最后再加上 \(val_x\),因为这时候 \(x\) 是 \(y\) 的儿子。预处理时间复杂度 \(O(n)\),单次询问跳倍增 \(O(\log n)\),总时间复杂 \(O(n + q \times \log n)\),可以通过此题。
# include <bits/stdc++.h>
# define int LL
# define vec vector
# define pb push_back
# define each1(i, x) for(auto (i) : (x))
# define each2(i, x) for(auto (&i) : (x))
# define rep(i, a, b) for(int i = (a); i <= (b); ++ i)
# define pre(i, a, b) for(int i = (a); i >= (b); -- i)
using namespace std;
using LL = long long;
const int N = 5e5 + 10;
int n, q;
int ln[N], sum[N], val[N], dp[N], deep[N], f[N][20];
vec<int> e[N];
void init(){
ln[1] = 0;
rep(i, 2, N - 10){
ln[i] = ln[i >> 1] + 1;
}
}
void dfs(int u, int fa){
sum[u] = val[u];
deep[u] = deep[fa] + 1;
f[u][0] = fa;
rep(i, 1, ln[deep[u]]) f[u][i] = f[f[u][i - 1]][i - 1];//预处理
each2(v, e[u]){
if(fa == v) continue;
dfs(v, u);
dp[u] += dp[v] + sum[v];
sum[u] += sum[v];
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
init();
cin >> n >> q;
rep(i, 1, n) cin >> val[i];
rep(i, 2, n){
int f;
cin >> f;
e[i].pb(f);
e[f].pb(i);
}
dfs(1, 0);
while(q --){
int x, y;
cin >> x >> y;
if(deep[y] == deep[x] - 1){
cout << dp[y] << "\n";
continue;
}
int z = x;
int s = ln[deep[z]];//倍增
while(s >= 0){
if(deep[f[z][s]] >= deep[y] + 1) z = f[z][s];
s --;
}
cout << dp[y] + sum[z] - sum[x] - val[x] * (deep[x] - deep[y]) + val[x] << "\n";
}
return 0;
}
T5 P11478 [COCI 2024/2025 #3] 处理器 / Procesor
没补,不会。
COCI 2024/2025 #3的更多相关文章
- Bzoj索引
1001 : http://ideone.com/4omPYJ1002 : http://ideone.com/BZr9KF1003 : http://ideone.com/48NJNh1004 : ...
- 分析java.lang.NullPointerException thrown in RelativeLayout measure()
典型的再现环境 模型: Sony Ericsson Android version: 2.3.4 StackTrace: E/AndroidRuntime( 3579): FATAL EXCEPTIO ...
- Hsql中In没有1000的限制
SELECT * FROM user , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...
- HDU 2021 发工资咯:)(最水贪心)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2021 发工资咯:) Time Limit: 2000/1000 MS (Java/Others) ...
- 转 nagios监控oracle运行状况
https://blog.csdn.net/heizistudio/article/details/8638488 nrpe安装脚本 nagios-plugins-1.4.13.tar.gznrpe- ...
- MATLAB之数学建模:深圳市生活垃圾处理社会总成本分析
MATLAB之数学建模:深圳市生活垃圾处理社会总成本分析 注:MATLAB版本--2016a,作图分析部分见<MATLAB之折线图.柱状图.饼图以及常用绘图技巧> 一.现状模式下的模型 % ...
- Java集合--TreeMap
转载请注明出处:http://www.cnblogs.com/skywang12345/admin/EditPosts.aspx?postid=3310928 第1部分 TreeMap介绍 TreeM ...
- Intent.java分析
代码位于frameworks/base/core/java/anroid/Content/Intent.java Intent是对要进行操作的一种抽象描述.用action抽象操作,用data(andr ...
- JS逆向-抠代码的第二天【手把手学会抠代码】
今天的学习项目:沃支付:https://epay.10010.com/auth/login 清空浏览器缓存后,打开网页,输入手机号,密码222222,按照网站要求填入验证码(sorry,我没有账号密码 ...
- android系统源码编译报错问题分析处理--持续更新
一.build/make/core/base_rules.mk:232: error: packages/services/Car/service: LOCAL_BUILT_MODULE and LO ...
随机推荐
- KubeSphere 社区双周报|2024.03.15-03.29
KubeSphere 社区双周报主要整理展示新增的贡献者名单和证书.新增的讲师证书以及两周内提交过 commit 的贡献者,并对近期重要的 PR 进行解析,同时还包含了线上/线下活动和布道推广等一系列 ...
- centos下搭建php开发环境(lamp)
由于个人非常喜欢爱linux系开发php项目. 因为某些原因,经常需要手动搭建环境 经常在网上找到的教程经常不太一样 虽然最终都能完成搭建,但是总是觉得不太爽 还不如自己写一篇,需要的时候肯定能找到 ...
- 修复一个kubernetes集群
前几天有个朋友把他们的kubernetes集群搞挂了,让我帮忙恢复一下,由于很多现场都没有了,这里提供一下解决思路. 环境问题 该环境有一个master节点,即控制面pod(etcd.schedule ...
- Linux基础-查看和设置环境变量
一,查看环境变量 二,环境变量类型 三,设置环境变量 四,参考资料 一,查看环境变量 在 Linux中,环境变量是一个很重要的概念.环境变量可以由系统.用户.Shell 以及其他程序来设定,其是保存在 ...
- 大模型推理指南:使用 vLLM 实现高效推理
本文主要分享如何使用 vLLM 实现大模型推理服务. 1. 概述 大模型推理有多种方式比如 最基础的 HuggingFace Transformers TGI vLLM Triton + Tensor ...
- 社区发布非官方龙架构 .NET 9 SDK 发行版
随着.NET 9的发布,龙芯的Loongarch 架构的.NET 9 SDK的发布也提上了日程,在龙芯.NET 的官方支持之外,今年在社区有一个非官方龙架构 .NET SDK 发行版(https:// ...
- python模块导入规则(相对导入和绝对导入)
python模块可以相对导入和绝对导入,但这两者是不能随意替换使用的.本文主要讨论工作目录下模块之间的导入规则.其中相对导入前面有一个'.',表示从该脚本所在目录开始索引,而绝对导入前面没有'.',表 ...
- (Redis基础教程之八) 如何在Redis中管理Sets
如何在ubuntu18.04上安装和保护redis 如何连接到Redis数据库 如何管理Redis数据库和Keys 如何在Redis中管理副本和客户端 如何在Redis中管理字符串 如何在Redis中 ...
- 方法区回收过程与GC的并发与并行
主要回收废弃常量和无用的类 废弃常量包括字面量.类或接口.方法.字段的符号引用等 废弃指的是没有任何地方引用这个常量. 无用的类 满足的三个条件: 1.没有该类的任何实例存在 2.加载该类的Class ...
- Linux之搭建sftp
0.查看openssh的版本 ssh -V #使用ssh -V 命令来查看openssh的版本,版本必须大于4.8p1,低于的这个版本需要升级. 1.创建sftp组 groupadd sftp ...