CSP-S模拟30

news/2025/10/15 21:14:25/文章来源:https://www.cnblogs.com/Wy-x/p/19144292

CSP-S模拟30

垃圾场

A. 灯若辰星 (light)

打表题。

题意就是求第一类、第二类斯特林数 \(\mod 2\) 意义下的值。

Code:

#include<bits/stdc++.h>
#define int long long using namespace std;const int Size=(1<<20)+1;
char buf[Size],*p1=buf,*p2=buf;
char buffer[Size];
int op1=-1;
const int op2=Size-1;
#define getchar()                                                              \
(tt == ss && (tt=(ss=In)+fread(In, 1, 1 << 20, stdin), ss == tt)     \? EOF                                                                 \: *ss++)
char In[1<<20],*ss=In,*tt=In;
inline int read()
{int x=0,c=getchar(),f=0;for(;c>'9'||c<'0';f=c=='-',c=getchar());for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c^48);return f?-x:x;
}
inline void write(int x)
{if(x<0) x=-x,putchar('-');if(x>9)  write(x/10);putchar(x%10+'0');
}int q;
int op,n,m;inline int f(int n,int m)
{int a=n/2,b=m-(n+1)/2;if((!n*m)||m>n) return 0;if(b<0||b>a) return 0;return ((a&b)==b);
}
inline int g(int n,int m)
{int a=n-1-m/2,b=n-m;if((!n*m)||m>n) return 0;if(b<0||b>a) return 0;return ((a&b)==b);
}inline void solve()
{op=read();n=read();m=read();if(n==0&&m==0) cout<<"1";else if(op==1) cout<<f(n,m);else cout<<g(n,m);
}signed main()
{freopen("light.in","r",stdin);freopen("light.out","w",stdout);q=read();while(q--) solve();
}

B. 彻天之火 (fire)

异或哈希。

答案 \(= n − 1−\) 交集的最大值。

对于每条边 \(i\),假设覆盖它的路径集合是 \(S_i\),那么出现次数最多的 \(S_i\) 的出现次数就是交集的最大值。

给每条路径随机一个 \([0, 2^63)\) 内的权值,每条边的权值取成覆盖它的路径权值的异或和,就可以大概率表示出不同的覆盖集合。

异或差分甚至不需要求出 lca,复杂度 \(O(n + m)\)

证明是对的很难。但手模发现这样做可以覆盖所有情况。

Code:

#include<bits/stdc++.h>
#define int long longusing namespace std;const int Size=(1<<20)+1;
char buf[Size],*p1=buf,*p2=buf;
char buffer[Size];
int op1=-1;
const int op2=Size-1;
#define getchar()                                                              \
(tt == ss && (tt=(ss=In)+fread(In, 1, 1 << 20, stdin), ss == tt)     \? EOF                                                                 \: *ss++)
char In[1<<20],*ss=In,*tt=In;
inline int read()
{int x=0,c=getchar(),f=0;for(;c>'9'||c<'0';f=c=='-',c=getchar());for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c^48);return f?-x:x;
}
inline void write(int x)
{if(x<0) x=-x,putchar('-');if(x>9)  write(x/10);putchar(x%10+'0');
}int n,m;
const int N=1<<20;
vector<int> E[1<<20];
int u[N],v[N];// int bcj[1<<20];
// int f[1<<20];
// int dep[1<<20];
// int find(int x)
// {
// 	if(x==bcj[x]) return x;
// 	return bcj[x]=find(bcj[x]);
// }int cntt;
mt19937_64 rnd(time(0));
// int val[N];
int pval[N];unordered_map<int,int> mp;void dfs(int p,int fa)
{// int nw=0;for(int to:E[p]){if(to==fa) continue;dfs(to,p);pval[p]^=pval[to];}if(p==1) return;// cout<<p<<" "<<pval[p]<<"\n";// mp[pval[p]]++;// cntt=max(cntt,mp[pval[p]]);// nw^=pval[p];mp[pval[p]]++;cntt=max(cntt,mp[pval[p]]);// pval[p]=nw;// f[p]=fa;// dep[p]=dep[fa]+1;// for(int to:E[p])// {// 	if(to==fa) continue;// 	dfs(to,p);// }
}// void init()
// {
// 	for(int i=1;i<=n;i++) bcj[i]=i;
// 	dfs(1,0);
// }// int Lca(int u,int v)
// {
// 	int cnt=0;
// 	while(bcj[u]!=bcj[v])
// 	{
// 		if(dep[u]<dep[v]) swap(u,v);
// 		cnt++;
// 		int top=find(u);
// 		bcj[top]=find(f[top]);
// 		u=bcj[top];
// 	}
// 	return cnt;
// }int solve1()
{return 0;// init();// int cnt=0;// for(int i=1;i<=m;i++)// {// 	cnt+=Lca(u[i],v[i]);// }// return cnt;
}int solve2()
{for(int i=1;i<=m;i++){int nw=(rnd()>>1);// cout<<nw<<"\n";pval[u[i]]^=nw;pval[v[i]]^=nw;}dfs(1,0);// cout<<cntt<<"\n";return cntt;
}signed main()
{// #ifndef ONLINE_JUDGEfreopen("fire.in","r",stdin);freopen("fire.out","w",stdout);n=read();m=read();for(int i=1;i<n;i++){int u=read(),v=read();E[u].push_back(v);E[v].push_back(u);}for(int i=1;i<=m;i++){u[i]=read();v[i]=read();// if(u[i]==v[i]) { i--,m--; }}int ans=max(solve1(),solve2());cout<<max(0ll,n-1-ans)<<"\n";// #endif//mt19937_64 myrand(time(0));return 0;
}

C. 完美记忆 (perfect)

Code:

D. 未来程序 (program)

Code:

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

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

相关文章

2025多校冲刺CSP模拟赛5

T1:小 Z 爱计数(count) 思路: 一道挂大分的签到题。 显然,我们要根据 \(a_i-a_{i-1}\) 值对输入数据进行排序,然后通过 \(a_i-a_{i-1}\) 与\(b_i-b_{i-1}\) 之间的值的比较来判断操作是否合法。这里我们根据 (题…

应用安全 --- 安卓神器 之 入口加密

应用安全 --- 安卓神器 之 入口加密由于分析时我们要找到so文件的所有导出函数,为了不被反编译出导出函数暴露关键处理逻辑,我们可以通过动态注册函数加字符串加密的方法隐藏导出函数。 解决方法: 解密字符串后找到…

读书报告和代码

《神经网络与深度学习:从理论到CIFAR-10实战》读书报告 一、引言 在人工智能蓬勃发展的当下,神经网络作为机器学习领域的核心技术,已在计算机视觉、自然语言处理等诸多领域展现出强大的能力。本次读书报告将围绕神经…

P66实训2

运行代码 import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import DataLoader from torchvision.datasets import CIFAR10 from torchvision.transforms import ToTensor, Nor…

《程序员的修炼之道:从小工到专家》阅读笔记

《程序员的修炼之道:从小工到专家》并非单纯的技术手册,而是程序员职业成长的指南。它跳出具体编码技巧,聚焦从 “小工” 到 “专家” 的核心素养修炼。 书中提出的 “DRY 原则”“正交性” 等理念,直指开发中的常…

关于Pytorch深度学习神经网络的读书报告

在深度学习领域,卷积神经网络(CNN)凭借其在图像识别、计算机视觉等任务中的卓越表现,成为新手入门深度学习时绕不开的重要知识点。而 PyTorch 作为一款简洁灵活的深度学习框架,为理解和实现 CNN 提供了极大的便利…

牛客刷题-Day13

优先队列、并查集 https://ac.nowcoder.com/acm/contest/22904?from=acdiscuss牛客刷题-Day13 今日刷题:\(1001-1005\) 1002 Running Median 题目描述 For this problem, you will write a program that reads in a …

蛋白表达标签:提升重组蛋白研究与生产的关键工具

蛋白表达标签:提升重组蛋白研究与生产的关键工具 在重组蛋白的生产与应用中,蛋白表达标签已成为不可或缺的工具。它们通过融合到目标蛋白的N端或C端,简化了蛋白的纯化、检测与稳定性管理。对于科研与工业用户而言,…

const int *p和int *const p快速区分

const int *p:其地址可变,内容不可变。个人记法为去掉int为const *p,const修饰*p,而*p又指其内容,所以内容不可变。 int * const p:其内容可变,地址不可变。个人记法为去掉int为*const p,const修饰p,p不可变则…

二分图、拓扑与欧拉

1、二分图匹配问题(判断是否二分图可以使用并查集) `// 邻接表存储图 int n1, n2, m; int h[500], e[100010],ne[100010], idx = 0; //st 标记是否递归找过, match[x]:和 x 编号的男生的编号 int st[510], match[5…

pytorch作业

import torch import torch.nn as nn import torch.optim as optim from torchvision import datasets, transforms from torch.utils.data import DataLoader import matplotlib.pyplot as plt =====================…

pytorch实验题作业

import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import DataLoader from torchvision import datasets, transforms import matplotlib.pyplot as plt 数据预处理:标准化+数…

每日笔记

忘了写了,但是没有关系,今天加油,今天学习了还健身了

Zhengrui #3346. DINO

被我暴力干过去了qwq。 你考虑一个事情,打开大样例,点击 .out 文件,发现几乎全是 \(0\),你想一想为什么,本质上是你的 \(mex\) 每增加 \(1\),你的点的数量就会至少翻一倍,也就是说,答案最多是 \(O(\log n)\) 级…

Pytorch深度学习训练

import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import DataLoader from torchvision import datasets, transforms import matplotlib.pyplot as plt 数据预处理:标准化+数…

P11894 「LAOI-9」Update

题意十分甚至有九分的简单,但是这个东西似乎是不好做的,我想不出来任何已知的 log 数据结构维护它。 突然发现这个东西增长是缓慢的,我于是乎写了个程序验证,最后发现答案最多是 1e6 左右的一个数。 果然有的时候观…

win10软实时设置 - 教程

win10软实时设置 - 教程2025-10-15 20:47 tlnshuju 阅读(0) 评论(0) 收藏 举报pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; fon…

实用指南:Hunyuan3D-Omni:可控3D资产生成的统一框架

实用指南:Hunyuan3D-Omni:可控3D资产生成的统一框架pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas&qu…

ZR 2025 NOIP 二十连测 Day 3

40 + 100 + 30 + 20 = 190, Rank 61/130.打满了。25noip二十连测day3 链接:link 题解:题目内 时间:4.5h (2025.10.15 13:40~18:10) 题目数:4 难度:A B C D\(\color{#FFC116} 黄\)*1500估分:40 + 100 + 15 + [5,?…

实用指南:2025年9月个人工作生活总结

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