【每日一题 | 2025】2.3 ~ 2.9

news/2025/2/12 18:56:00/

在这里插入图片描述

个人主页:GUIQU.
归属专栏:每日一题

在这里插入图片描述

文章目录

  • 1. 【2.3】P8784 [蓝桥杯 2022 省 B] 积木画
  • 2. 【2.4】P8656 [蓝桥杯 2017 国 B] 对局匹配
  • 3. 【2.5】[ABC365D] AtCoder Janken 3
  • 4. 【2.6】P8703 [蓝桥杯 2019 国 B] 最优包含
  • 5. 【2.7】P8624 [蓝桥杯 2015 省 AB] 垒骰子
  • 6. 【2.8】P8774 [蓝桥杯 2022 省 A] 爬树的甲壳虫
  • 7. 【2.9】[ARC189C] Balls and Boxes

正文

1. 【2.3】P8784 [蓝桥杯 2022 省 B] 积木画

题目链接:https://www.luogu.com.cn/problem/P8784

【AC_Code】

#include <iostream>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);using namespace std;const int mod = 1e9 + 7;
int N;int main()
{IOS; cin >> N;if (N == 1){cout << 1 << "\n";return 0;}if (N == 2){cout << 2 << "\n";return 0;}if (N == 3){cout << 5 << "\n";return 0;}int a = 1, b = 2, c = 5, d;for (int i = 4; i <= N; i ++){d = c * 2 % mod + a;a = b, b = c, c = d;a %= mod, b %= mod, c %= mod, d %= mod;}cout << d << "\n";return 0;
}

2. 【2.4】P8656 [蓝桥杯 2017 国 B] 对局匹配

题目链接:https://www.luogu.com.cn/problem/P8656

【AC_Code】

#include <iostream>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);using namespace std;const int maxN = 1e5 + 10;
int N, K, index, ans, a[maxN];int main()
{IOS; cin >> N >> K;for (int i = 0; i < N; i ++) cin >> index, a[index] ++;if (K == 0){for (int i = 0; i < N; i ++) if (a[i]) ans ++;cout << ans << "\n";return 0;}for (int i = 0; i < maxN; i ++){if (a[i] < a[i + K]) a[i + K] -= a[i];else a[i + K] = 0;}for (int i = 0; i < maxN - K; i ++) ans += a[i];cout << ans << "\n";return 0;
}

3. 【2.5】[ABC365D] AtCoder Janken 3

题目链接:https://www.luogu.com.cn/problem/AT_abc365_d

【AC_Code】

#include <bits/stdc++.h>
#define int long longusing namespace std;const int N = 2e5 + 10;
int n, ans, f[N][10];
string s;int main()
{cin >> n >> s;if (s[0] == 'R') {f[0][1] = 0;f[0][2] = 1;}if (s[0] == 'P') {f[0][2] = 0;f[0][3] = 1;}if (s[0] == 'S') {f[0][1] = 1;f[0][3] = 0;}for (int i = 1; i < n; i++) {if (s[i] == 'R') {f[i][1] = max(f[i - 1][2], f[i - 1][3]);f[i][2] = max(f[i - 1][1], f[i - 1][3]) + 1;}if (s[i] == 'P') {f[i][2] = max(f[i - 1][1], f[i - 1][3]);f[i][3] = max(f[i - 1][1], f[i - 1][2]) + 1;}if (s[i] == 'S') {f[i][1] = max(f[i - 1][2], f[i - 1][3]) + 1;f[i][3] = max(f[i - 1][1], f[i - 1][2]);}}cout << max({f[n - 1][1], f[n - 1][2], f[n - 1][3]});return 0;
}

4. 【2.6】P8703 [蓝桥杯 2019 国 B] 最优包含

题目链接:https://www.luogu.com.cn/problem/P8703

【AC_Code】

#include <iostream>
#include <cstring>
#include <algorithm>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define inf 0x3f3f3f3fusing namespace std;const int maxn = 1010;
int dp[maxn][maxn];
string S, T;int main()
{IOS; cin >> S >> T; S = " " + S, T = " " + T;memset(dp, inf, sizeof(dp));for (int i = 0; i < S.size() + 1; i ++) dp[i][0] = 0;for (int i = 1; i <= S.size(); i ++) for (int j = 1; j <= S.size(); j ++){if (S[i] == T[j]) dp[i][j] = dp[i-1][j-1];else dp[i][j] = min(dp[i-1][j-1]+1, dp[i-1][j]);}cout << dp[S.size()][T.size()] << "\n";return 0;
}

5. 【2.7】P8624 [蓝桥杯 2015 省 AB] 垒骰子

题目链接:https://www.luogu.com.cn/problem/P8624

【AC_Code】

#include<bits/stdc++.h>
using namespace std;
#define rep(x,y,z) for(int x=y;x<=z;x++)
typedef long long LL;
const int mod=1e9+7;
int n,m,a,b,oppo[7]={0,4,5,6,1,2,3};
bool st[7][7];
struct matrix{LL c[7][7];matrix(){memset(c,0,sizeof c);}
}A,res;
matrix operator * (matrix &x,matrix &y){matrix t;rep(i,1,6){rep(j,1,6){rep(k,1,6){t.c[i][j]=(t.c[i][j]+x.c[i][k]*y.c[k][j])%mod;}}}return t;
}
void fastpow(LL k){rep(i,1,6) res.c[1][i]=4;rep(i,1,6){rep(j,1,6){if(st[i][oppo[j]]) A.c[i][j]=0;else A.c[i][j]=4;}}while(k){if(k&1) res=res*A;A=A*A;k>>=1;}
}int main()
{cin>>n>>m;while(m--){cin>>a>>b;st[a][b]=st[b][a]=1;}fastpow(n-1);LL ans=0;rep(i,1,6) ans=(ans%mod+res.c[1][i]%mod)%mod;cout<<ans;return 0;
}

6. 【2.8】P8774 [蓝桥杯 2022 省 A] 爬树的甲壳虫

题目链接:https://www.luogu.com.cn/problem/P8774

【AC_Code】

#include <bits/stdc++.h>using namespace std;const int N = 1e5 + 5;
const int P = 998244353;int n, a[N], b[N];int fp(int x, int y) {int res = 1;for (; y; y >>= 1) {if (y & 1) {res = (1ll * res * x) % P;}x = (1ll * x * x) % P;}return res;
}int main() {scanf("%d", &n);for (int i = 1; i <= n; i++) {scanf("%d%d", &a[i], &b[i]);}int s1 = 1, s2 = 0, s3 = 0;for (int i = 1; i <= n; i++) {int p1 = (1ll * a[i] * fp(b[i], P - 2)) % P;int p2 = (1ll * (b[i] - a[i]) * fp(b[i], P - 2)) % P;s3 = (s3 + s1) % P;s2 = (s2 + 1ll * s1 * p1) % P;s1 = (1ll * s1 * p2) % P;}printf("%d", (1ll * s3 * fp(1 - s2 + P, P - 2)) % P);return 0;
}

7. 【2.9】[ARC189C] Balls and Boxes

题目链接:https://www.luogu.com.cn/problem/AT_arc189_c

【AC_Code】

#include <bits/stdc++.h>#define F(i, a, b) for (int i = (a); i <= (b); ++i)
#define dF(i, a, b) for (int i = (a); i >= (b); --i)using namespace std;typedef long long LL;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pii;const int N = 2e5 + 5;int n, x, a[N], b[N], p[N], q[N];
int m, k, s[N], t[N], tt[N];
bool vis[N];int dp[N], c[N], ans;void Update(int x, int k) {while (x <= n) {c[x] = max(c[x], k);x += x & -x;}
}void Query(int &y, int x) {while (x) {y = max(y, c[x]);x -= x & -x;}
}int main()
{ios::sync_with_stdio(0);cin.tie(0), cout.tie(0);cin >> n >> x;F(i, 1, n) {cin >> a[i];}F(i, 1, n) {cin >> b[i];}F(i, 1, n) {cin >> p[i];}F(i, 1, n) {cin >> q[i];}int u = p[x];bool now = 0;vis[x] = 1;while (!vis[u]) {now |= a[u];vis[u] = 1;if (now) {s[++m] = u;}u = p[u];}F(i, 1, n) {if (!vis[i] && a[i]) {return cout << "-1", 0;}}F(i, 1, n) {vis[i] = 0;}u = q[x];now = 0;vis[x] = 1;while (!vis[u]) {now |= b[u];vis[u] = 1;if (now) {t[++k] = u;}u = q[u];}F(i, 1, n) {if (!vis[i] && b[i]) {return cout << "-1", 0;}}F(i, 1, k) {tt[t[i]] = i;}F(i, 1, m) {if (tt[s[i]]) {Query(dp[i], tt[s[i]]);Update(tt[s[i]], ++dp[i]);}}F(i, 1, n) {ans = max(ans, dp[i]);}cout << m + k - ans;return 0;
}

结语
感谢您的阅读!期待您的一键三连!欢迎指正!

在这里插入图片描述


http://www.ppmy.cn/news/1571499.html

相关文章

HTTP 请求方式`application/x-www-form-urlencoded` 与 `application/json` 怎么用?有什么区别?

HTTP 请求方式总结&#xff1a;application/x-www-form-urlencoded 与 application/json 在前后端交互中&#xff0c;客户端发送数据到服务器的常见方式有两种&#xff1a;application/x-www-form-urlencoded 和 application/json。本文将详细介绍这两种请求方式的特点、使用方…

Flink-序列化

一、概述 几乎每个Flink作业都必须在其运算符之间交换数据&#xff0c;由于这些记录不仅可以发送到同一JVM中的另一个实例&#xff0c;还可以发送到单独的进程&#xff0c;因此需要先将记录序列化为字节。类似地&#xff0c;Flink的堆外状态后端基于本地嵌入式RocksDB实例&…

鸿蒙音视频播放器:libwlmedia

libwlmedia 跨平台播放器wlmedia现在已经支持了鸿蒙(Harmony)平台了&#xff0c;SDK插件地址&#xff1a;libwlmedia 一、接入SDK 1.1 导入SDK ohpm i ywl5320/libwlmedia1.2 添加权限&#xff08;可选&#xff09; 如果需要播放网络视频&#xff0c;需要添加网络权限 #m…

华为Mate 70 Pro或推出全新版本

关于华为Mate 70 Pro或推出全新版本的相关内容&#xff1a;可能的版本及命名。 据数码博主“定焦数码”爆料&#xff0c;华为Mate 70 Pro将推出新版本&#xff0c;命名为“优享版”。这一命名方式与华为Mate 60系列中的Mate 60 Pro乐臻版类似&#xff0c;预计优享版也会是一个组…

【编程实践】vscode+pyside6环境部署

1 PySide6简介 PySide6是Qt for Python的官方版本&#xff0c;支持Qt6&#xff0c;提供Python访问Qt框架的接口。优点包括官方支持、LGPL许可&#xff0c;便于商业应用&#xff0c;与Qt6同步更新&#xff0c;支持最新特性。缺点是相比PyQt5&#xff0c;社区资源较少。未来发展…

DeepSeek和ChatGPT的对比

最近DeepSeek大放异彩&#xff0c;两者之间有什么差异呢&#xff1f;根据了解到的信息&#xff0c;简单做了一个对比。 DeepSeek 和 ChatGPT 是两种不同的自然语言处理&#xff08;NLP&#xff09;模型架构&#xff0c;尽管它们都基于 Transformer 架构&#xff0c;但在设计目标…

Reflexxes Type II 机器人和运动控制系统的实时运动规划库

Reflexxes Type II 是德国 Reflexxes GmbH 公司开发的一套用于机器人和运动控制系统的实时运动规划库&#xff0c;以下从主要功能、核心算法、应用场景、使用优势等方面介绍其主要内容&#xff1a; 主要功能 轨迹生成&#xff1a;能够在极短时间内为机器人或运动系统生成平滑…

STM32 硬件I2C读写MPU6050

接线图 函数介绍 生成起始条件 void I2C_GenerateSTART(I2C_TypeDef* I2Cx, FunctionalState NewState); 生成终止条件 void I2C_GenerateSTOP(I2C_TypeDef* I2Cx, FunctionalState NewState); 配置在收到一个字节后&#xff0c;是否给从机应答&#xff08;配置ACK位&…