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 ...
随机推荐
- 基于 JuiceFS 的 KubeSphere DevOps 项目数据迁移方案
方案背景和目的 KubeSphere 自发布以来已有 2 年之久,从 2.1.0 版本至目前最新版本 3.3.开发人员的编译构建都基于环境平台的 DevOps 功能(底层是 jenkins)实现,如果 ...
- 云原生爱好者周刊:非容器化应用也需要 Docker Compose
开源项目推荐 Process Compose Process Compose 是一个调度编排工具,不过不是用来调度容器的,而是用来调度非容器化的应用,可以定义进程的依赖性和启动顺序,也可以定义重启策略 ...
- 三大主流负载均衡软件对比(LVS+Nginx+HAproxy)
LVS: 优点 : 1.抗负载能力强.性能高,能达到F5硬件的60%:对内存和cpu资源消耗比较低2.工作在网络4层,通过vrrp协议转发(仅作分发之用),具体的流量由linux内核处理,因此没有流量 ...
- 在Ubuntu小设备上使用VSCode+SSH开发部署nicegui的Web应用,并设置系统开机自动启动应用
在一些小的设备上跑Ubuntu系统,需要快速的开发和调整项目的时候,往往使用SSH进行远程的开发测试,这样可以避免传统的打包更新处理,能够快速的在实际环境上测试具体的内容.另外由于系统设备往往需要重启 ...
- Value error: 'ascii' codec can't decode byte 0xe6 in position 26: ordinal not in range(128) The traceback for the exception was written to the log file
原因:工作空间中有中文编码问题,导致的运行ros异常 解决办法: 1.解决urdf生成异常问题 urdf文件中不允许有中文,所有当输入中文的时候容易出问题,解决方案: ①在根目录下:/opt/ros/ ...
- 工作中的技术总结_JQuery_20210825
工作中的技术总结_JQuery_20210825 JQuery此前接触不多,所以先把此次接触的一些基本操作 1.DOM节点的取值或者赋值: 语法: $(selector).val(value) 参数 ...
- 开源 - Ideal库 - 常用枚举扩展方法(一)
今天和大家享一些关于枚举操作相关的常用扩展方法. 我们平时用的比较多的是正常枚举,同时还有加[Flags]特性的位标志枚举,因此以下所有扩展方法同时适用正常枚举以及位标志枚举. 我们首先定义两种枚举用 ...
- SyntaxError: non-default argument follows default argument
有时候没注意就会犯一些低级错误 问题原因 把没有默认值的形参放到了带有默认值的形参后面 解决办法 问了一下chatgpt,果然一语道破.因为python在定义函数时,在不定长参数中,默认值参数不能放在 ...
- dotnet学习笔记-专题06-过滤器和中间件-01
1. 基本概念 在ASP.NET Core中,中间件和过滤器都是处理HTTP请求的重要组件,但它们在应用中的位置.作用范围以及使用方式有所不同. 1.1 中间件和过滤器的区别 1.1.1 中间件 位置 ...
- YAML语法基础
YAML 的意思其实是:"Yet Another Markup Language"(仍是一种标记语言). YAML 的语法和其他高级语言类似,并且可以简单表达清单.散列表,标量等数 ...