脑瘫记

· · 个人记录

本文同步发布于博客园

CSP-S 2023

考完后别人一说 T1 样例什么意思我就会了,然后回来切了,T2 也用栈50。 # NOIP 1 ![](https://cdn.luogu.com.cn/upload/image_hosting/amua0rby.png) ![](https://cdn.luogu.com.cn/upload/image_hosting/ab8pum3e.png) 本地输出和评测输出不一样 原因:使用 ```ch[i][j]=getchar()``` 导致的 # NOIP 3 ## SPJ不能卡时!!! T4模拟退火 ```cpp if((double)clock()/CLOCKS_PER_SEC>0.98){ for(register int i=1;i<=n;i++){ WritE(ans[i]); } // cerr<<endl<<Ans; // cerr<<endl<<(double)clock()/CLOCKS_PER_SEC; exit(0); } ``` 但是它special judge还需要约100ms测我的数据导致我TLE了,喜挂12pts。 改成 ```cpp if((double)clock()/CLOCKS_PER_SEC>0.7){ for(register int i=1;i<=n;i++){ WritE(ans[i]); } // cerr<<endl<<Ans; // cerr<<endl<<(double)clock()/CLOCKS_PER_SEC; exit(0); } ``` 即可。 # NOIP 4 ![](https://cdn.luogu.com.cn/upload/image_hosting/ge4j861r.png) T2 50->10 lower_bound 没 ```sort``` 导致的。 ```cpp auto pos=s.lower_bound(op); if(pos==s.end()){ return !puts("No"); } s.erase(*pos); ``` # NOIP 11 ![](https://cdn.luogu.com.cn/upload/image_hosting/xt93kfuv.png) ![](https://cdn.luogu.com.cn/upload/image_hosting/y5i5otdl.png) 特盘 ```!m``` 忘了写 ```return 0;``` 导致输出了两倍的答案。挂20分 UU 吧80分卡成50了 ![](https://cdn.luogu.com.cn/upload/image_hosting/xdo3roxi.png) # NOIP2023模拟15 ## T2 退火骗到了 $n\le 100$,但是没打宝搜导致 $n\le 10$ 和 $n\le 25$ 没对,挂 $25$分。 ## T1 好不容易写出方程 $$\begin{cases} ax-by=c\\ x+y=2^w \end{cases}$$ 求 $w$ 最小值。 但是不会解方程导致我没写出来,挂?80昏。 枚举 $w$, 解得 $y=\frac{2^w a-c}{a+b}$,判断一下是否小于 $2^w$ 即可。 ```cpp #include<bits/stdc++.h> #define byd void #define int long long using namespace std; namespace Testify{ int read(){ int f(1),x(0); char ch=getchar(); for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-1; for(;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+(ch^48); return f*x; } void WritE(int x){ if(x<0) putchar('-'),x=-x; if(x>9) WritE(x/10); putchar(x%10+48); } void write(int x){ WritE(x); puts(""); } void Write(int x){ WritE(x); putchar(' '); } } using namespace Testify; const int N=1e5+5; int a,b,c,d,p,q; inline int qpow(int a,int b,int mod){ int res=1; for(;b;b>>=1,a=a*a%mod){ if(b&1){ res=res*a%mod; } } return res; } signed main(byd){ freopen("a.in","r",stdin); freopen("a.out","w",stdout); p=read(),q=read(); for(;q;q--){ a=read(),b=read(),c=read(),d=read(); if((a+b)%p!=(c+d)%p){ puts("-1"); continue; } bool flag=false; int inv=qpow(a+b,p-2,p); for(register int i=0;i<=30;i++){ int y=(((1ll<<i)*a-c+p)%p)*inv%p; if(y<(1ll<<i)){ write(i); flag=true; break; } } if(!flag){ puts("-1"); } } return 0; } /* 10 3 8 8 1 5 9 8 10 7 2 5 5 2 */ ``` ## T4 多项式题 被题目名字诈骗了导致只写了宝搜,实际上非常简单。 设 $dp_i$ 为前 $i$ 项的和。 $$Sum(l,r)=sum_r-sum_{l-1}\times BASE_{r-l+1}$$ $$dp_i=\sum_{j=0}^{j-1}(dp_j\times Sum(j+1,i))$$ 用前缀和维护 $\sum$ 即可得到 $O(n)$ 狮子 $$dp_i=sum_i\times\sum\limits_{j=0}^{i-1}dp_j-10^j\times \sum\limits_{j=0}^{i-1}(10^{-j}sum_jdp_j)$$ ```cpp #include<bits/stdc++.h> #define int long long using namespace std; namespace Testify{ int read(){ int f(1),x(0); char ch=getchar(); for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-1; for(;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+(ch^48); return f*x; } void WritE(int x){ if(x<0) putchar('-'),x=-x; if(x>9) WritE(x/10); putchar(x%10+48); } void write(int x){ WritE(x); puts(""); } void Write(int x){ WritE(x); putchar(' '); } } using namespace Testify; const int mod=998244353; int n,m; const int N=2e5+5; char ch[N]; bool vis[N]; int sum[N],SATELLITE=0,bAse[N]; inline int A39(int l,int r){ return (sum[r]-(sum[l-1]*bAse[r-l+1]%mod)+mod)%mod; } int dp[N]; int sum1[N],sum2[N],BasE[N]; inline int qpow(int a,int b){ int res=1; for(;b;b>>=1,a=a*a%mod){ if(b&1){ res=res*a%mod; } } return res; } signed main(void){ freopen("d.in","r",stdin); freopen("d.out","w",stdout); n=read(); scanf("%s",ch+1); bAse[0]=1; BasE[0]=1; for(register int i=1;i<=n;i++){ sum[i]=(sum[i-1]*10+(ch[i]-'0'))%mod; bAse[i]=bAse[i-1]*10%mod; BasE[i]=BasE[i-1]*qpow(10,mod-2)%mod; } dp[0]=1; sum1[0]=1,sum2[0]=0; for(register int i=1;i<=n;i++){ dp[i]=(sum[i]*sum1[i-1]%mod-(bAse[i]*sum2[i-1]%mod)+mod)%mod; sum1[i]=(sum1[i-1]+dp[i])%mod; sum2[i]=(sum2[i-1]+BasE[i]*sum[i]%mod*dp[i])%mod; } write(dp[n]); return 0; } /* 20 69938314042683453883 5 12345 */ ``` ## NOIP a层31 ![](https://cdn.luogu.com.cn/upload/image_hosting/o6xai0fq.png) 我草初始化为0没想到答案是0,原来是没初始化为 $-1$ 导致的 ![](https://cdn.luogu.com.cn/upload/image_hosting/00c9yni6.png) 我去提交题录有100分后面把sort换成直接找结果挂了30混。