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的更多相关文章

  1. Bzoj索引

    1001 : http://ideone.com/4omPYJ1002 : http://ideone.com/BZr9KF1003 : http://ideone.com/48NJNh1004 : ...

  2. 分析java.lang.NullPointerException thrown in RelativeLayout measure()

    典型的再现环境 模型: Sony Ericsson Android version: 2.3.4 StackTrace: E/AndroidRuntime( 3579): FATAL EXCEPTIO ...

  3. Hsql中In没有1000的限制

    SELECT * FROM user , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...

  4. HDU 2021 发工资咯:)(最水贪心)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2021 发工资咯:) Time Limit: 2000/1000 MS (Java/Others)    ...

  5. 转 nagios监控oracle运行状况

    https://blog.csdn.net/heizistudio/article/details/8638488 nrpe安装脚本 nagios-plugins-1.4.13.tar.gznrpe- ...

  6. MATLAB之数学建模:深圳市生活垃圾处理社会总成本分析

    MATLAB之数学建模:深圳市生活垃圾处理社会总成本分析 注:MATLAB版本--2016a,作图分析部分见<MATLAB之折线图.柱状图.饼图以及常用绘图技巧> 一.现状模式下的模型 % ...

  7. Java集合--TreeMap

    转载请注明出处:http://www.cnblogs.com/skywang12345/admin/EditPosts.aspx?postid=3310928 第1部分 TreeMap介绍 TreeM ...

  8. Intent.java分析

    代码位于frameworks/base/core/java/anroid/Content/Intent.java Intent是对要进行操作的一种抽象描述.用action抽象操作,用data(andr ...

  9. JS逆向-抠代码的第二天【手把手学会抠代码】

    今天的学习项目:沃支付:https://epay.10010.com/auth/login 清空浏览器缓存后,打开网页,输入手机号,密码222222,按照网站要求填入验证码(sorry,我没有账号密码 ...

  10. android系统源码编译报错问题分析处理--持续更新

    一.build/make/core/base_rules.mk:232: error: packages/services/Car/service: LOCAL_BUILT_MODULE and LO ...

随机推荐

  1. 一文搞定 KubeKey 3.1.1 离线部署 KubeSphere 3.4.1 和 Kubernetes v1.28

    本文将详细介绍,如何基于操作系统 openEuler 22.03 LTS SP3,利用 KubeKey 制作 KubeSphere 和 Kubernetes 离线安装包,并实战部署 KubeSpher ...

  2. Ubuntu 22.04 全局快捷键失效问题

    安装完 Ubuntu 22.04 后,你有可能会发现系统的快捷键失效了.侧栏用 Win + x 选中程序不可用了.为各种应用程序设置的快捷键也不起作用了. 出现此现象的原因,是因为 Ubuntu 22 ...

  3. Effective C++:以const、enum和inline来替换define

    替换define,也就是"以编译器替换预处理器".#define是C语言里的利器,但在C++里有很多取代它的理由. define是预处理的一部分,而不是编译器的一部分,它在编译前就 ...

  4. 狂神说-Docker基础-学习笔记-07 容器数据卷

    狂神说-Docker基础-学习笔记-07 容器数据卷 视频地址:https://www.bilibili.com/video/BV1og4y1q7M4?p=21 什么是容器数据卷 运行时数据都在容器中 ...

  5. 远程连接服务器时出现“这可能是由于CredSSP加密数据库修正”的错误提示的解决办法

    当我们远程连接服务器时,有时候会出现以下提示,从而导致我们无法成功连接服务器,如下所述: 原因: 远程桌面使用的是"凭据安全支持提供程序协议 (CredSSP) ",这个协议在未修 ...

  6. SqlSugarClient 代码优先建表, 根据给定的实体类,创建SQL语句, 之后创建MySQL表

    using SqlSugar; using System; using System.Collections.Generic; using System.Reflection; using Syste ...

  7. Auto-Encoding Variational Bayes (VAE原文)、变分推理

    变分自动编码器的大致概念已经理解了快一年多了,但是其中的数学原理还是没有搞懂,在看到相关的变体时,总会被数学公式卡住.下决心搞懂后,在此记录下我的理解. 公式推导--变分下界 这篇文章提出一种拟合数据 ...

  8. memcached 和 Grails,第 1 部分:安装和使用 memcached

    学习 memcached 命令并评估缓存性能 本文是系列文章的第 1 部分,主要介绍 memcached 和 Grails.作者 James Goodwill 将向您介绍开源解决方案 memcache ...

  9. golang之errors包

    errors包常用方法 func Unwrap(err error) error // 获得err包含下一层错误 func Is(err, target error) bool // 判断err是否包 ...

  10. [转载]Redis之缓存穿透、缓存击穿、缓存雪崩及其解决方法

    原文地址:https://mp.weixin.qq.com/s?__biz=MzU2MDY0NDQwNQ==&mid=2247483949&idx=1&sn=6c643858d ...