【比赛记录】2025CSP-S模拟赛1

A. Alice 和璀璨花

做法和正常 LIS 类似。设 \(dp_{i,j}\) 表示在前 \(i\) 个中选 \(j\) 个的最小结尾显然对于相同的 \(i\)\(dp\) 值单调递增。二分出 \(dp_{i-1}\) 中第一个 \(\ge i\) 的位置 \(k\)。对于 \([0,k-1]\) 的部分,显然不用转移;对于 \([k+1,n]\) 的部分,\(a_i\) 显然不可能大于 \(dp\times b\)。于是只在 \(k\) 处做转移即可。滚掉一维,空间复杂度 \(O(n)\),时间复杂度 \(O(n\log n)\)

Code
复制代码
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
#include<bits/stdc++.h> #define ll long long #define il inline #define lwrb lower_bound using namespace std; namespace asbt{ namespace cplx{bool begin;} const int maxn=1e6+5; const ll inf=0x3f3f3f3f3f3f3f3f; int n; ll a[maxn],b[maxn],dp[maxn]; namespace cplx{ bool end; il double usdmem(){return (&begin-&end)/1048576.0;} } int main(){ freopen("alice.in","r",stdin); freopen("alice.out","w",stdout); ios::sync_with_stdio(0),cin.tie(0); cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<=n;i++){ cin>>b[i]; } memset(dp,0x3f,sizeof dp); dp[0]=0; for(int i=1,tmp;i<=n;i++){ tmp=lwrb(dp,dp+n+1,a[i])-dp; if(dp[tmp-1]*b[tmp-1]<a[i]){ dp[tmp]=a[i]; } } for(int i=n;i;i--){ if(dp[i]<inf){ cout<<i; return 0; } } return 0; } } int main(){return asbt::main();}

B. Bob 与幸运日

\(n\le 10^3\) 的点直接枚举。
式子:

\[\begin{cases} \begin{align} &(x-1)d+y\equiv a&\pmod w&\\ &(y-1)d+x\equiv b&\pmod w& \end{align} \end{cases} \]

\((1)+(2)\),得

\[(x+y)(d+1)\equiv a+b+2d\pmod w \]

\((1)-(2)\),得

\[(x-y)(d-1)\equiv a-b\pmod w \]

移项求逆元即可(如果有逆元)。数据随机那个包就是给这个的。

50pts Code
复制代码
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
#include<bits/stdc++.h> #define int long long #define il inline using namespace std; namespace asbt{ namespace cplx{bool begin;} int T,m,d,w,a,b; il int qpow(int x,int y,int p){ int res=1; while(y){ if(y&1){ (res*=x)%=p; } (x*=x)%=p,y>>=1; } return res; } namespace cplx{ bool end; il double usdmem(){return (&begin-&end)/1048576.0;} } signed main(){ freopen("bob.in","r",stdin); freopen("bob.out","w",stdout); ios::sync_with_stdio(0),cin.tie(0); cin>>T; while(T--){ cin>>m>>d>>w>>a>>b; int n=min(m,d); if(n<=1e3){ int ans=0; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(((i-1)*d+j-1)%w==a-1&&((j-1)*d+i-1)%w==b-1){ ans++; } } } cout<<ans<<"\n"; continue; } int p=(a+b+2*d)%w*qpow(d+1,w-2,w)%w; int q=(b-a)%w*qpow(d-1,w-2,w)%w; (p+=w)%=w,(q+=w)%=w; int x=(p+q)%w*qpow(2,w-2,w)%w; int y=(p-q)%w*qpow(2,w-2,w)%w; (x+=w)%=w,(y+=w)%=w; int nx=n/w,ny=n/w; if(n%w>=x){ nx++; } if(n%w>=y){ ny++; } cout<<nx*ny<<"\n"; } return 0; } } signed main(){return asbt::main();}

C. Charlie 的运输网

D. David 与和谐号

posted @   zhangxy__hp  阅读(11)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
展开