2024.7.28 模拟赛10
1.2024.7.18模拟赛12.2024.7.19模拟赛23.2024.7.20模拟赛34.2024.7.21模拟赛45.2024.7.22模拟赛56.2024.7.23 模拟赛67.2024.7.25模拟赛78.2024.7.26模拟赛89.2024.7.27模拟赛9
10.2024.7.28 模拟赛10
11.2024.7.29模拟赛1112.2024.7.31模拟赛1213.2024.8.1 模拟赛1314.2024.8.6 模拟赛 1415.2024.8.7 模拟赛 1516.2024.8.8模拟赛1617.2024.8.10模拟赛1718.2024.8.18 模拟赛 2219.2024.8.19 模拟赛 2420.小集训21.2024.9.23 模拟赛 CSP 322.2024.9.24 模拟赛 CSP423.2024.9.25 模拟赛 多校24.2024.9.27 模拟赛 CSP525.2024.9.28 模拟赛 CSP626.2024.9.30 模拟赛 CSP727.2024.10.7 模拟赛 多校328.2024.?.?? 模拟赛 ???模拟赛
T1 Company Acquisitions
鞅的停时定理。
赛时应该不可做的吧。
手膜两组样例发现肯定不能用常规方法做。然后开始新科技。
势能函数!!!
设计一个势能函数去表示一种状态,这个势能函数要满足每操作一步势能减一,这样初势能减末势能就是期望步数。
(是不是直接把势能差看成期望步数就行?)
对于本道题来说,设
我们想要找出势能函数之间的递推关系,对于任意两个点,显然有以下式子:
对
由于
转化成等比数列的形式(注意是负数):
然后就很简单啦!(所以鞅的停时定理是啥?)(好像真的是板子题)
附赠小饼干 Slime and Biscuits + 快踩
code
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 1e6+5,mod = 1e9+7;
int n,a[N];
LL ans;
inline LL qpow(LL a,LL b)
{
LL res=1;
while(b)
{
if(b&1) res=res*a%mod;
a=a*a%mod; b>>=1;
}
return res;
}
int main()
{
// freopen("in.in","r",stdin);
// freopen("out.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
int x; scanf("%d",&x);
if(x!=-1) a[x]++;
}
for(int i=1;i<=n;i++)
if(a[i]) ans=(ans-qpow(2,a[i])+1+mod)%mod;
ans=(ans+qpow(2,n-1)-1+mod)%mod;
printf("%lld\n",ans);
return 0;
}
T2 数学作业
又是矩阵加速板子。。。
突破点在递推关系,每加一个数
因此我们可以用 dp 的方法解决。而数据范围暗示了矩阵加速。
因为位数是不定的,所以考虑按数字长度分段进行操作。复杂度带一个
注意 __int128
。
code
#include<bits/stdc++.h>
using namespace std;
#define LL __int128
long long n,m;
struct M
{
LL x,y,mat[4][4]={};
M operator * (const M &a) const
{
M c; c.x=x; c.y=a.y;
for(int i=1;i<=x;i++)
for(int j=1;j<=a.y;j++)
for(int k=1;k<=y;k++)
c.mat[i][j]=(c.mat[i][j]+mat[i][k]*a.mat[k][j]%m)%m;
return c;
}
};
M qpow(M a,M b,LL c)
{
while(c)
{
if(c&1) a=(a*b);
b=(b*b); c>>=1;
}
return a;
}
int main()
{
// freopen("in.in","r",stdin);
// freopen("out.out","w",stdout);
scanf("%lld%lld",&n,&m);
M a,b;
a.x=1; a.y=b.x=b.y=3;
a.mat[1][2]=a.mat[1][3]=1;
b.mat[2][1]=b.mat[2][2]=b.mat[3][2]=b.mat[3][3]=1;
for(LL i=1,j=1;;i++)
{
j=b.mat[1][1]=j*10;//注意 j 不要 mod
b.mat[1][1]%=m;
if(n<j)
{
a=qpow(a,b,n-j/10+1);
break;
}
a=qpow(a,b,j-j/10);
}
printf("%lld\n",(long long)a.mat[1][1]);
return 0;
}
T3 「P6156 简单题」加强版
开始莫反。。。
求:令
则
两次前缀和就可以了。
然后考虑筛
再考虑
考虑欧拉筛筛中
根据积性函数性质,则有:
讨论一下
,即 的取值一定为 。 ,则 。 ,则 。 ,由于鸽笼原理,此时 和 中至少有一个能被 整除,则那一个的 的值为 。所以此时 。
(借鉴一下)
code
#include<bits/stdc++.h>
using namespace std;
const int N = 2e7+5;
#define LL unsigned int
LL p[N],f[N],F[N],n,k,t;
bool vs[N];
inline LL qpow(LL a,LL b)
{
LL res=1;
while(b)
{
if(b&1) res=res*a;
a=a*a; b>>=1;
}
return res;
}
inline void init()
{
f[1]=F[1]=1;
for(int i=2;i<=n<<1;i++)
{
if(!vs[i]) f[i]=i-1,F[i]=qpow(i,k),p[++p[0]]=i;
for(int j=1;j<=p[0]&&i*p[j]<=n<<1;j++)
{
vs[p[j]*i]=1; F[i*p[j]]=F[i]*F[p[j]];
if(i%p[j]==0)
{
if((i/p[j])%p[j]) f[i*p[j]]=(-p[j])*f[i/p[j]];
break;
}
f[p[j]*i]=f[i]*(p[j]-1);
}
}
for(int i=2;i<=n<<1;i++) f[i]=(f[i-1]+f[i]*F[i]),F[i]=(F[i-1]+F[i]);
for(int i=2;i<=n<<1;i++) F[i]=(F[i-1]+F[i]);
}
inline LL cal(LL x)
{
return ((F[x<<1]-(F[x]<<1)));
}
int main()
{
// freopen("in.in","r",stdin);
// freopen("o1.out","w",stdout);
scanf("%u%u%u",&t,&n,&k);
init();
while(t--)
{
scanf("%u",&n);
LL ans=0;
for(int l=1,r;l<=n;l=r+1)
{
r=(n/(n/l));
ans=(ans+((f[r]-f[l-1]))*cal(n/l));
}
printf("%u\n",ans);
}
return 0;
}
T4
图
水题放 T4。。。
没啥,直接数位 dp 相当好写(其实没有 dp),其实直接贪也行吧。
code
#include<bits/stdc++.h>
using namespace std;
const int N = 30;
#define LL long long
LL n;
int len,ans,a[N];
int dfs(int p,int sum,bool c)
{
if(!p) return sum;
if(!c) return sum+9*p;
int res=0;
res=max(dfs(p-1,sum+a[p],1),a[p]-1>=0?dfs(p-1,sum+a[p]-1,0):0);
return res;
}
int work(LL x)
{
len=0; while(x) a[++len]=x%10,x/=10;
return dfs(len,0,1);
}
int main()
{
// freopen("in.in","r",stdin);
// freopen("out.out","w",stdout);
scanf("%lld",&n);
printf("%d\n",work(n));
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端