当前位置: 首页 > news >正文

CSP-S模拟30

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.hskmm.com/?act=detail&tid=31840

相关文章:

  • 2025多校冲刺CSP模拟赛5
  • float
  • 读书报告和代码
  • P66实训2
  • 《程序员的修炼之道:从小工到专家》阅读笔记
  • 关于Pytorch深度学习神经网络的读书报告
  • 牛客刷题-Day13
  • 蛋白表达标签:提升重组蛋白研究与生产的关键工具
  • const int *p和int *const p快速区分
  • 二分图、拓扑与欧拉
  • pytorch作业
  • pytorch实验题作业
  • 每日笔记
  • Zhengrui #3346. DINO
  • Pytorch深度学习训练
  • P11894 「LAOI-9」Update
  • ZR 2025 NOIP 二十连测 Day 3
  • 读书报告
  • P14223 [ICPC 2024 Kunming I] 乐观向上
  • 别再用均值填充了!MICE算法教你正确处理缺失数据
  • 非主流网站程序IndexNow添加方法
  • 卷积神经网络视频读书报告
  • C 语言 - 内存操作函数以及字符串操作函数解析
  • 以*this返回局部对象的两种情况
  • 2025.10.15
  • 软件开发流程
  • Kali 自定义ISO镜像
  • 2025秋_12
  • 10月15日
  • 第七章:C控制语句:分支和跳转