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. ABC343:起航

    ABC343:起航 2024/3/2/22:53 有点儿晚了,简单总结一下. 前4题都很基础,一点点小思维,其中C题 边界又盲目追求刚刚好,WA了一次,总结经验,程序实际设计应该略微大于数据范围. E ...

  2. 2个月搞定计算机二级C语言——真题(10)解析

    1. 前言 本篇我们讲解2个月搞定计算机二级C语言--真题10 2. 程序填空题 2.1 题目要求 2.2 提供的代码 #include <stdio.h> #pragma warning ...

  3. Verilog代码规范

    历史修改信息 版本 更改描述 更改人 批准人 修订日期/生效日期 A01 发布首版 ldy 一.目的 作为我司verilog开发过程中的输入文件,用于统一FPGA开发人员的代码风格.从而在满足功能和性 ...

  4. iptables防火墙规则介绍与配置

    防火墙简单介绍 防火墙根据什么对外网的进出数据流进行控制? 源IP.目标IP.源端口号.目标端口号.协议.指针位(SYN.FIN.ACK.RST).状态(NEW.ESTABLISHED.INVIAD) ...

  5. 10.Kubernetes核心技术Service

    Kubernetes核心技术Service 前言 前面我们了解到 Deployment 只是保证了支撑服务的微服务Pod的数量,但是没有解决如何访问这些服务的问题.一个Pod只是一个运行服务的实例,随 ...

  6. 干货分享:Air780E怎么连接华为云?

    ​ 众所周知,市面上有很多云平台,阿里云.腾讯云.中移OneNET.华为云.百度云.涂鸦云.TLink云等等......并且每家云平台都有自己的协议,工程师要移植不同的SDK代码或基于各家的手册文档对 ...

  7. ElementUI ---- dialog点击取消后蒙遮层不消失

    场景: 页面A打开了 dialog, 然后点击 页面A dialog 的按钮 跳转到 页面B,并且打开页面B的 dialog 但是页面B的 dialog 关闭后,蒙遮层并没消失(已经设置了 :appe ...

  8. (Redis基础教程之九) 如何在Redis中使用Sorted Sets

    介绍 Redis是一个开源的内存中键值数据存储.在Redis的,排序集合类似于一个数据类型集在这两者都是串的非重复的组.不同之处在于,已排序集中的每个成员都与一个分数相关联,从而可以从最小分数到最大分 ...

  9. JVM源码分析-Java运行

    最近在看Java并发编程实践和Inside JVM两本书,发现如果不真正的了解底层运作,那么永远是雾里看花.因此从http://openjdk.java.net/groups/hotspot/上下载了 ...

  10. input输入框与button按钮之间存在空隙

    出现空隙是写代码的时候换行导致的,给input框加上float:left 可解决