QBXT2025S刷题 Day4

news/2025/10/5 22:47:46/文章来源:https://www.cnblogs.com/SigmaToT/p/19127133

今天的题
\(75pts\ rk50+\) ,最废的一次。

T1

简单 \(\mathcal{DP}\)

#include <iostream>using std::cin;
using std::cout;
const int N = 1e3 + 10;
#define int long long
const int mod = 998244353;int a[N][N];
char c[N][N];
int f[N][N][2];
int g[N][N][2];
int cnt[N][N][2];signed main()
{int n, m;cin >> n >> m;for (int i = 1; i <= n; ++i){for (int j = 1; j <= m; ++j)cin >> c[i][j];}if ((n == 1 && m == 1) || (c[1][1] == '#') || (c[n][m] == '#')){cout << 0 << '\n';return 0;}for (int i = 1; i <= n; ++i){for (int j = 1; j <= m; ++j)a[i][j] = 1ll * i * j % mod;}if (m >= 2 && c[1][2] == '.'){cnt[1][2][0] = 1;f[1][2][0] = 2;g[1][2][0] = 2;}if (n >= 2 && c[2][1] == '.'){cnt[2][1][1] = 1;f[2][1][1] = 2;g[2][1][1] = 2;}for (int i = 1; i <= n; ++i){for (int j = 1; j <= m; ++j){if (c[i][j] == '#' || (i == 1 && j == 1))continue;if (i > 1 && c[i - 1][j] != '#'){if (f[i - 1][j][1]){cnt[i][j][1] = (cnt[i][j][1] + cnt[i - 1][j][1]) % mod;f[i][j][1] = (1ll * f[i][j][1] + f[i - 1][j][1] + 1ll * cnt[i - 1][j][1] * a[i][j] % mod) % mod;g[i][j][1] = (1ll * g[i][j][1] + g[i - 1][j][1] + f[i - 1][j][1] + 1ll * a[i][j] * cnt[i - 1][j][1] % mod) % mod;}if (f[i - 1][j][0]){cnt[i][j][1] = (cnt[i][j][1] + cnt[i - 1][j][0]) % mod;f[i][j][1] = (1ll * f[i][j][1] + 1ll * cnt[i - 1][j][0] * a[i][j] % mod) % mod;g[i][j][1] = (1ll * g[i][j][1] + 1ll * g[i - 1][j][0] + cnt[i - 1][j][0] * a[i][j] % mod) % mod;}}if (j > 1 && c[i][j - 1] != '#'){if (f[i][j - 1][0]){cnt[i][j][0] = (cnt[i][j][0] + cnt[i][j - 1][0]) % mod;f[i][j][0] = (1ll * f[i][j][0] + f[i][j - 1][0] + 1ll * cnt[i][j - 1][0] * a[i][j] % mod) % mod;g[i][j][0] = (1ll * g[i][j][0] + g[i][j - 1][0] + f[i][j - 1][0] + 1ll * a[i][j] * cnt[i][j - 1][0] % mod) % mod;}if (f[i][j - 1][1]){cnt[i][j][0] = (cnt[i][j][0] + cnt[i][j - 1][1]) % mod;f[i][j][0] = (1ll * f[i][j][0] + 1ll * cnt[i][j - 1][1] * a[i][j] % mod) % mod;g[i][j][0] = (1ll * g[i][j][0] + g[i][j - 1][1] + 1ll * cnt[i][j - 1][1] * a[i][j] % mod) % mod;}}}}cout << (1ll * g[n][m][0] + g[n][m][1]) % mod;return 0;
}

T2

虚树 \(or\) 重链剖分 \(or\) 结论。
我用的是结论。
取dfn排序的中位数。
那么答案肯定是这个中位数的某个祖先,直接倍增就行。

#include <iostream>
#include <vector>
#include <algorithm>
#define lowbit(x) x & (-x)using std::cin;
using std::cout;
const int N = 1e5 + 10;int k;
int idx;
int dep[N];
int dfn[N];
int sum[N];
int size[N];
int fa[N][25];
std::vector<int> now;
std::vector<int> e[N];void dfs(int x, int father)
{dep[x] = dep[father] + 1;dfn[x] = ++idx;fa[x][0] = father;for (int i = 1; i <= 20; ++i)fa[x][i] = fa[fa[x][i - 1]][i - 1];for (auto to : e[x]){if (to != father)dfs(to, x);}size[x] = 1;for (auto to : e[x]){if (to != father)size[x] += size[to];}
}
void add(int x, int k)
{for (; x <= idx; x += lowbit(x))sum[x] += k;
}
int query(int x)
{int ret = 0;for (; x; x -= lowbit(x))ret += sum[x];return ret;
}
int ask(int l, int r)
{return query(r) - query(l - 1);
}
int where(int x)
{if (ask(dfn[x], dfn[x] + size[x] - 1) > (k / 2))return x;for (int i = 20; i >= 0; --i){int l = fa[x][i];if (l && ask(dfn[l], dfn[l] + size[l] - 1) <= k / 2)x = l;}	return fa[x][0];
}int main()
{int n;cin >> n;for (int i = 1; i < n; ++i){int u, v;cin >> u >> v;e[u].push_back(v);e[v].push_back(u);}dfs(1, 0);int q;cin >> q;while (q--){now.clear();cin >> k;for (int i = 1; i <= k; ++i){int s;cin >> s;now.push_back(s);add(dfn[s], 1);}std::sort(now.begin(), now.end(), [&](const int &a, const int &b){return dfn[a] < dfn[b];});k = now.size();if (now.size() & 1)cout << where(now[(now.size() >> 1)]) << '\n';else{int x = where(now[now.size() >> 1]);int y = where(now[(now.size() >> 1) - 1]);cout << (dep[x] > dep[y] ? x : x) << '\n';}for (auto it : now)add(dfn[it], -1);}return 0;
}

T3

找欧拉回路。
奇数加一条边,偶数加两条边。

#include <iostream>
#include <vector>
#include <stack>using std::cin;
using std::cout;
const int N = 12e5 + 10;int idx;
int top;
int w[N];
bool vis[N];
int lst[N];
int deg[N];
int stk[N];
std::vector<int> odd;
std::vector<int> gg[N];void add(int x, int y)
{w[++idx] = x ^ y;gg[x].push_back(idx);gg[y].push_back(idx);
}
void dfs(int x)
{for (int i = lst[x]; i < (int)gg[x].size(); i = lst[x]){lst[x] = std::max(lst[x], i + 1);int to = w[gg[x][i]] ^ x;if (!vis[gg[x][i]]){vis[gg[x][i]] = true;dfs(to);stk[++top] = to;}}
}int main()
{int n, m;cin >> n >> m;for (int i = 1; i <= m; ++i){int u, v;cin >> u >> v;int t;cin >> t;if (t & 1){add(u, v);deg[v]++;deg[u]++;}else{add(u, v);add(u, v);deg[v] += 2;deg[u] += 2;}}for (int i = 1; i <= n; ++i){if (deg[i] & 1)odd.push_back(i);}if (odd.size() == 1 || odd.size() > 2){cout << -1 << '\n';return 0;}if (odd.size() == 0){dfs(1);stk[++top] = 1;cout << top << '\n';for (int i = top; i >= 1; --i)cout << stk[i] << ' ';cout << '\n';}else{add(odd[0], odd[1]);dfs(odd[0]);int ge;for (int i = 1; i <= top; ++i){for (int j = 0; j <= 1; ++j){if (stk[i] == odd[j] && stk[i % top + 1] == odd[j ^ 1]){ge = i;break;}}}cout << top << '\n';for (int i = ge; i >= 1; --i)cout << stk[i]<< ' ';for (int i = top; i >= ge + 1; --i)cout << stk[i] << ' ';cout << '\n';}return 0;
}

T4

容斥。
image
image

#include<bits/stdc++.h>
using namespace std;int read();
typedef long long ll;
#define fr(i,l,r) for(int i=(l);i<=(r);++i)
#define rf(i,l,r) for(int i=(l);i>=(r);--i)
#define fo(i,l,r) for(int i=(l);i<(r);++i)
#define foredge(i,u,v) for(int i=fir[u],v;v=to[i],i;i=nxt[i])
#define filein(file) freopen(file".in","r",stdin)
#define fileout(file) freopen(file".out","w",stdout)const int N=1e6+5,MOD=1e9+7;
int n,m,k;
ll fac[N],ifac[N];
ll qpow(ll a,int x) {ll z=1;for(;x;x>>=1,a=a*a%MOD)if(x&1) z=z*a%MOD;return z;
}
ll C(int n,int m) {if(n<m) return 0;return fac[n]*ifac[m]%MOD*ifac[n-m]%MOD;
}
int main() {//filein("count");//fileout("count");cin>>n>>m>>k;*fac=1; fr(i,1,m) fac[i]=fac[i-1]*i%MOD;ifac[m]=qpow(fac[m],MOD-2);rf(i,m,1) ifac[i-1]=ifac[i]*i%MOD;ll ans=0,sum=0;sum=1;rf(i,m,0) {(ans+=(i&1?-1:1)*C(m,i)*qpow(sum-1,n))%=MOD;sum=(sum*2-C(m-i,k))%MOD;//sum=\sum_{j=0}^k C(m-i,j)}cout<<(ans+MOD)%MOD<<endl;return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/928812.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

实用指南:2025年05月29日Github流行趋势

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

java学习日记9.25

9.25 学习笔记 类型转换由于Java是强类型语言,所以要进行有些运算的时候,需要用到类型转换。大小排序:byte, short,char-int-long-float[^1]-double运算中,不同类型的数据先转化为同一类型,然后进行运算。强制转换…

porting 开源memtester

1.下载代码 https://pyropus.ca./software/memtester/old-versions/ 目前用的版本是4.5.1 2.修改交叉编译器,并进行编译 arm-linux-gnueabihf-gcc3.指令 ./memtester 200M 5

广东省建设注册执业资格中心网站jae安装wordpress

当前示例源码github地址: https://github.com/vilyLei/voxwebgpu/blob/version-1.01/src/voxgpu/sample/MultiMaterialPass.ts 此示例渲染系统实现的特性: 1. 用户态与系统态隔离。 2. 高频调用与低频调用隔离。 3. 面向用户的易用性封装。 4. 渲染数据和渲染机制分离。 …

江西省建设监理协会网站广州门户网站

目录 问题&#xff1a; 解决办法&#xff1a; 1.打开设置 2. 取消勾选 3.点击确认 4.解决 问题提出&#xff1a; 写shi山的过程中&#xff0c;给模块取错名字了&#xff0c;改名的时候不知道点到了什么&#xff0c;一个模块的pom.xml变成灰色了&#xff0…

上海专业网站建设维护wordpress后台进

Elasticsearch的Mapping Mapping是什么 Mapping定义了ES的索引结构、字段类型、分词器等&#xff0c;是索引的一部分。类似于关系型数据库中“表结构”的概念&#xff0c;在 Mapping 里也包含了一些属性&#xff0c;比如字段名称、类型、字段使用的分词器、是否评分、是否创建…

完整教程:用mediamtx搭建简易rtmp,rtsp视频服务器

完整教程:用mediamtx搭建简易rtmp,rtsp视频服务器pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas"…

查找网站后台入口丝绸之路网站建设报告

安装Jenkins成功之后&#xff0c;首次启动Jenkins后台管理&#xff0c;进入到安装插件的步骤&#xff0c;选择"推荐安装"&#xff0c;继续下一步的时候出现错误提示&#xff1a; 出现一个错误 安装过程中出现一个错误&#xff1a;No such plugin&#xff1a;cloudb…

百度免费网站申请注册企业贷款

蓝桥集训之三国游戏 核心思想&#xff1a;贪心 将每个事件的贡献值求出 降序排序从大到小求和为正是即可 #include <iostream>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;const int N 100010;int a[N],b[N],c[N];…

oppoR9m MTK 6755 开启VCOM的9008模式

前言全局说明oppoR9m MTK 6755 开启VCOM的9008模式注意:刷机,会丢失用户:照片、聊天等信息资料。请备份基带等信息。请慎重刷机 !!! 注意:刷机,会丢失用户:照片、聊天等信息资料。请备份基带等信息。请慎重刷机 …

关于电脑息屏后自动亮屏的的原因排查及解决方式

1、问题描述 大约在 2025 年 9 月初的时候,我的联想拯救者笔记本电脑出现了锁屏息屏一段时间后自动亮屏的现象,在半夜时特别引人注意。 2、原因排查 经排查,我发现是联想壁纸服务的问题:异常现象发生后,锁屏壁纸不…

版本设计网站wordpress 试题

平台为了保证统一性&#xff0c;做了很多约定&#xff0c;例如按钮图标等&#xff0c;平台规定图标取自这两个地方。在整个平台上运行的系统必须保持一致。在这个层面上不允许个性发挥。 1) font-awesome import font-awesome/css/font-awesome.min.css // font-awesome …

angular2做的网站有设计风格网站欣赏

文章目录 1. 题目2. 思路及代码实现&#xff08;Python&#xff09;2.1 二分查找2.2 划分数组 1. 题目 给定两个大小分别为 m m m 和 n n n 的正序&#xff08;从小到大&#xff09;数组 nums1 和 nums2。请你找出并返回这两个正序数组的 中位数 。 算法的时间复杂度应该为…

机器人世界杯工业联赛技术解析

本文深入探讨RoboCup@Work工业机器人联赛的技术细节,包括自主导航、物体抓取、传感器集成等关键技术,以及机器人硬件架构和软件系统的演进,展现了工业自动化领域的前沿研究进展。RoboCup@Work League:专访Christop…

HTML基础学习 - 教程

HTML基础学习 - 教程pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "…

Squarepoint Challenge (Codeforces Round 1055, Div. 1 + Div. 2) A~E

A - Increase or Smash 模拟。 对于每个不是最大值的来说,都会经历一次先置为零然后再加的操作,重复项只计算一次;而最大值不用置为零,所以最开始会有一次。点击查看代码 #include <bits/stdc++.h>using nam…

k8s之基础概念

1. k8s 架构K8s 属于经典的主从模型(Master-Slave 架构),由 Master 和 Node 节点构成:Master 节点:负责集群的管理,协调集群中的所有活动。例如应用的运行、修改、更新等。 Node 节点:为 Kubernetes 集群中的工…

Java基础 Day26 - 详解

Java基础 Day26 - 详解pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", &quo…

14_mklink创建符号链接

Win11中使用mklink创建符号链接完全指南 引言 在Windows 11系统中,文件和文件夹的管理是我们日常使用电脑的重要组成部分。有时候,我们希望能够在不移动实际文件的情况下,让文件或文件夹在多个位置"同时存在&q…

7_如何构建知识图谱

第一步:确定知识图谱的领域和范围 构建知识图谱的第一步是明确定义其目的、覆盖的领域和边界。这一步至关重要,因为它决定了整个项目的方向和复杂度。 1. 确定应用场景和目标问答系统:为特定领域提供智能问答服务 搜…