2024初三集训模拟测试3
1.初中信息奥赛模拟测试2.2024初三年前集训测试13.2024初三年前集训测试24.2024初三年前集训测试35.2024初三集训模拟测试16.2024初三集训模拟测试2
7.2024初三集训模拟测试3
8.集训 4 & 模拟 59.初三奥赛模拟测试110.NOIP2024模拟111.NOIP2024模拟212.暑假集训CSP提高模拟113.暑假集训CSP提高模拟4 & 暑假集训CSP提高模拟514.模拟赛2515.暑假集训CSP提高模拟716.暑假集训CSP提高模拟2 & 暑假集训CSP提高模拟317.10.4 - 11.4 改题纪要18.2024.8.9 鲜花19.2024.10.22 鲜花20.2024.10.23 鲜花21.11.4 - 12.3122.2024.11.12 鲜花23.2024.11.14 鲜花24.2024.11.26 鲜花25.2024.1.15 鲜花26.2024.2.17 鲜花2024初三集训模拟测试3
-
T1 排序:
显然贪心。
将
1ll*a[i]*a[i-1]
1ll*(a[i]*a[i-1])
囍爆零CODE
#include<bits/stdc++.h> using namespace std; using llt=long long; using ull=unsigned long long; #define For(i,a,b,c) for(int i=(a);i<=(b);i+=(c)) #define For_(i,a,b,c) for(int i=(a);i>=(b);i-=(c)) const int N=1e5+3; int n,a[N<<2]; namespace IO{ template<class T> inline void write(T x){ static T st[45];T top=0;if(x<0)x=-x,putchar('-'); do{st[top++]=x%10;}while(x/=10);while(top)putchar(st[--top]^48); } template<class T> T READ_NONPARAMETRIC_INIT; template<class T = int> inline T read(T &x=READ_NONPARAMETRIC_INIT<T>){ char s=getchar();x=0;bool pd=false;while(s<'0'||'9'<s){if(s=='-') pd=true;s=getchar();} while('0'<=s&&s<='9'){x=x*10+(s^48),s=getchar();} return (pd?(x=-x):x); } } namespace IO{ char NL_C; double NL_F; long double NL_LF; inline char read(char &c){c=getchar();while(c<33||c>126) c=getchar();return c;} template<int MAXSIZE=INT_MAX> inline int read(char* c){ char s=getchar();int pos=0;while(s<33||s>126) s=getchar(); while(s>=33&&s<=126&&pos<MAXSIZE) c[pos++]=s,s=getchar();c[pos]='\0';return pos; } template<int MAXSIZE=INT_MAX> inline int read(string &c){ c.clear();char s=getchar();int pos=0;while(s<33||s>126) s=getchar(); while(s>=33&&s<=126&&pos<MAXSIZE) c.push_back(s),s=getchar(),pos++;return pos; } inline double read(double &x){scanf("%lf",&x);return x;} inline long double read(long double &x){scanf("%Lf",&x);return x;} template<class T,class... Args> inline void read(T& x,Args&... args){read(x);read(args...);} inline void write(char c){putchar(c);} inline void write(char *c){int len=strlen(c);For(i,0,len-1,1) putchar(c[i]);} inline void write(string &c){int len=c.size();For(i,0,len-1,1) putchar(c[i]);} inline void write(const char *c){int len=strlen(c);For(i,0,len-1,1) putchar(c[i]);} template<int PRECISION=6> inline void write(double x){printf("%.*lf",PRECISION,x);} template<int PRECISION=6> inline void write(long double x){printf("%.*Lf",PRECISION,x);} template<class T> inline void Write(T x){write(x),putchar(' ');} inline void Write(char c){write(c);if(c!='\n') putchar(' ');} inline void Write(char *c){write(c);if(c[strlen(c)-1]!='\n') putchar(' ');} inline void Write(string &c){write(c);if(c[c.size()-1]!='\n') putchar(' ');} inline void Write(const char *c){write(c);if(c[strlen(c)-1]!='\n') putchar(' ');} template<class T,class... Args> inline void write(T x,Args... args){write(x);write(args...);} template<class T,class... Args> inline void Write(T x,Args... args){Write(x);Write(args...);} } using namespace IO; int main(){ #ifndef ONLINE_JUDGE freopen("in.in","r",stdin); freopen("out.out","w",stdout); #endif read(n); For(i,1,n<<2,1) read(a[i]); sort(a+1,a+(n<<2)+1); llt ans=0; For(i,1,n,1) ans-=1ll*a[i]*a[(n<<1)-i+1]; For_(i,n<<2,(n<<1)+1,2) ans+=1ll*a[i]*a[i-1]; write(ans); } -
T2 牛吃草:
显然二分答案。
考虑
验证。设
表示在前 个选、不选的方案数。显然转移。
但是要单调队列优化,
因为有个常数不好转移,可以同一加上
,再在查询时减掉。CODE
#include<bits/stdc++.h> using namespace std; using llt=long long; using ull=unsigned long long; #define For(i,a,b,c) for(int i=(a);i<=(b);i+=(c)) #define For_(i,a,b,c) for(int i=(a);i>=(b);i-=(c)) const int N=5e5+3; int n,w[N],s,dp[N][2],que[N],hd,tl=1; namespace IO{ template<class T> inline void write(T x){ static T st[45];T top=0;if(x<0)x=-x,putchar('-'); do{st[top++]=x%10;}while(x/=10);while(top)putchar(st[--top]^48); } template<class T> T READ_NONPARAMETRIC_INIT; template<class T = int> inline T read(T &x=READ_NONPARAMETRIC_INIT<T>){ char s=getchar();x=0;bool pd=false;while(s<'0'||'9'<s){if(s=='-') pd=true;s=getchar();} while('0'<=s&&s<='9'){x=x*10+(s^48),s=getchar();} return (pd?(x=-x):x); } } namespace IO{ char NL_C; double NL_F; long double NL_LF; inline char read(char &c){c=getchar();while(c<33||c>126) c=getchar();return c;} template<int MAXSIZE=INT_MAX> inline int read(char* c){ char s=getchar();int pos=0;while(s<33||s>126) s=getchar(); while(s>=33&&s<=126&&pos<MAXSIZE) c[pos++]=s,s=getchar();c[pos]='\0';return pos; } template<int MAXSIZE=INT_MAX> inline int read(string &c){ c.clear();char s=getchar();int pos=0;while(s<33||s>126) s=getchar(); while(s>=33&&s<=126&&pos<MAXSIZE) c.push_back(s),s=getchar(),pos++;return pos; } inline double read(double &x){scanf("%lf",&x);return x;} inline long double read(long double &x){scanf("%Lf",&x);return x;} template<class T,class... Args> inline void read(T& x,Args&... args){read(x);read(args...);} inline void write(char c){putchar(c);} inline void write(char *c){int len=strlen(c);For(i,0,len-1,1) putchar(c[i]);} inline void write(string &c){int len=c.size();For(i,0,len-1,1) putchar(c[i]);} inline void write(const char *c){int len=strlen(c);For(i,0,len-1,1) putchar(c[i]);} template<int PRECISION=6> inline void write(double x){printf("%.*lf",PRECISION,x);} template<int PRECISION=6> inline void write(long double x){printf("%.*Lf",PRECISION,x);} template<class T> inline void Write(T x){write(x),putchar(' ');} inline void Write(char c){write(c);if(c!='\n') putchar(' ');} inline void Write(char *c){write(c);if(c[strlen(c)-1]!='\n') putchar(' ');} inline void Write(string &c){write(c);if(c[c.size()-1]!='\n') putchar(' ');} inline void Write(const char *c){write(c);if(c[strlen(c)-1]!='\n') putchar(' ');} template<class T,class... Args> inline void write(T x,Args... args){write(x);write(args...);} template<class T,class... Args> inline void Write(T x,Args... args){Write(x);Write(args...);} } using namespace IO; namespace DQ{ struct Q{int t,id;}que[N]; int hd=1,tl=0; inline void Clr(){hd=1,tl=0;} inline void Add(int x,int id){ while(hd<=tl&&que[tl].t<x) tl--; que[++tl]={x,id}; } inline int Get(int l){ while(hd<=tl&&que[hd].id<l) hd++; if(hd>tl) return 0; return que[hd].t; } } inline bool check(int sz){ memset(dp,0,sizeof dp); DQ::Clr(); For(i,1,n,1){ if(i>=sz) DQ::Add(max(dp[i-sz][1],dp[i-sz][0])+n-(i-sz),i-sz); dp[i][0]=max(dp[i-1][1],dp[i-1][0]); dp[i][1]=max(dp[i][1],DQ::Get(i-w[i])+i-n); } if(max(dp[n][0],dp[n][1])<s) return 0; else return 1; } int main(){ #ifndef ONLINE_JUDGE freopen("in.in","r",stdin); freopen("out.out","w",stdout); #endif read(n); For(i,1,n,1) read(w[i]); read(s);s=ceil(n*1.0/100*s); int l=1,r=n; while(l<=r){ int mid=(l+r)>>1; if(check(mid)) l=mid+1; else r=mid-1; } write(r); } -
T3 树上的宝藏:
考虑先不更换,显然树形 DP。
因为只能换一条,可以考虑换根,枚举到
子节点 时转移。这里用了
表示不更换以 为根选、不选的方案数, 表示不更换以 为根选、不选的方案, 表示将 替换后选、不选的方案。可以少用一个,但无所谓。
CODE
#include<bits/stdc++.h> using namespace std; using llt=long long; using ull=unsigned long long; #define For(i,a,b,c) for(int i=(a);i<=(b);i+=(c)) #define For_(i,a,b,c) for(int i=(a);i>=(b);i-=(c)) const int N=3e5+4,MOD=998244353; int n,dp[N][2],ans[N][2],fa[N],s[N][2]; struct DG{int x,y;}nw; queue<DG> que; namespace IO{ template<class T> inline void write(T x){ static T st[45];T top=0;if(x<0)x=-x,putchar('-'); do{st[top++]=x%10;}while(x/=10);while(top)putchar(st[--top]^48); } template<class T> T READ_NONPARAMETRIC_INIT; template<class T = int> inline T read(T &x=READ_NONPARAMETRIC_INIT<T>){ char s=getchar();x=0;bool pd=false;while(s<'0'||'9'<s){if(s=='-') pd=true;s=getchar();} while('0'<=s&&s<='9'){x=x*10+(s^48),s=getchar();} return (pd?(x=-x):x); } } namespace IO{ char NL_C; double NL_F; long double NL_LF; inline char read(char &c){c=getchar();while(c<33||c>126) c=getchar();return c;} template<int MAXSIZE=INT_MAX> inline int read(char* c){ char s=getchar();int pos=0;while(s<33||s>126) s=getchar(); while(s>=33&&s<=126&&pos<MAXSIZE) c[pos++]=s,s=getchar();c[pos]='\0';return pos; } template<int MAXSIZE=INT_MAX> inline int read(string &c){ c.clear();char s=getchar();int pos=0;while(s<33||s>126) s=getchar(); while(s>=33&&s<=126&&pos<MAXSIZE) c.push_back(s),s=getchar(),pos++;return pos; } inline double read(double &x){scanf("%lf",&x);return x;} inline long double read(long double &x){scanf("%Lf",&x);return x;} template<class T,class... Args> inline void read(T& x,Args&... args){read(x);read(args...);} inline void write(char c){putchar(c);} inline void write(char *c){int len=strlen(c);For(i,0,len-1,1) putchar(c[i]);} inline void write(string &c){int len=c.size();For(i,0,len-1,1) putchar(c[i]);} inline void write(const char *c){int len=strlen(c);For(i,0,len-1,1) putchar(c[i]);} template<int PRECISION=6> inline void write(double x){printf("%.*lf",PRECISION,x);} template<int PRECISION=6> inline void write(long double x){printf("%.*Lf",PRECISION,x);} template<class T> inline void Write(T x){write(x),putchar(' ');} inline void Write(char c){write(c);if(c!='\n') putchar(' ');} inline void Write(char *c){write(c);if(c[strlen(c)-1]!='\n') putchar(' ');} inline void Write(string &c){write(c);if(c[c.size()-1]!='\n') putchar(' ');} inline void Write(const char *c){write(c);if(c[strlen(c)-1]!='\n') putchar(' ');} template<class T,class... Args> inline void write(T x,Args... args){write(x);write(args...);} template<class T,class... Args> inline void Write(T x,Args... args){Write(x);Write(args...);} } using namespace IO; namespace MT{ inline int Fpw(int a,int b){ int ans=1; while(b){ if(b&1) ans=1ll*ans*a%MOD; a=1ll*a*a%MOD,b>>=1; } return ans; } inline int Inv(int a){return Fpw(a%MOD,MOD-2);} }using MT::Inv; namespace TO{ int hd[N],nt[N<<1],to[N<<1],tot; inline void Add(int u,int v){to[++tot]=v,nt[tot]=hd[u],hd[u]=tot;} #define For_to(i,u,v) for(int i=TO::hd[u],v=TO::to[i];i;i=TO::nt[i],v=TO::to[i]) } inline void Dfs1(int u,int f){ fa[u]=f,dp[u][0]=dp[u][1]=1; For_to(i,u,v) if(v!=f){ Dfs1(v,u); dp[u][1]=1ll*dp[v][0]*dp[u][1]%MOD; dp[u][0]=1ll*(dp[v][1]+dp[v][0])*dp[u][0]%MOD; } } inline int Get0(int u){return 1ll*s[fa[u]][0]*Inv(dp[u][1]+dp[u][0])%MOD;} inline int Get1(int u){return 1ll*s[fa[u]][1]*Inv(dp[u][0])%MOD;} inline void Dfs2(int u,int f){ if(f){ s[u][0]=(Get0(u)+Get1(u))%MOD; s[u][1]=(Get0(u))%MOD; }else s[u][0]=s[u][1]=1; For_to(i,u,v) if(v!=f){ s[u][0]=1ll*s[u][0]*(dp[v][0]+dp[v][1])%MOD; s[u][1]=1ll*s[u][1]*dp[v][0]%MOD; } For_to(i,u,v) if(v!=f){ ans[v][0]=1ll*Get1(v)*dp[v][0]%MOD; ans[v][1]=1ll*(Get0(v)+Get1(v))*dp[v][1]%MOD; Dfs2(v,u); } } int main(){ #ifndef ONLINE_JUDGE freopen("in_out/in.in","r",stdin); freopen("in_out/out.out","w",stdout); #endif read(n); For(i,1,n-1,1){ int u,v;read(u,v);que.push(DG{u,v}); TO::Add(u,v),TO::Add(v,u); } Dfs1(1,0); Dfs2(1,0); while(!que.empty()){ int u=que.front().x,v=que.front().y;que.pop(); if(fa[u]==v) swap(u,v); write((ans[v][0]+ans[v][1])%MOD,'\n'); } } -
T4 MEX:
不会,先咕了。
本文来自博客园,作者:5k_sync_closer,转载请注明原文链接:https://www.cnblogs.com/xrlong/p/18028210
版权声明:本作品采用 「署名-非商业性使用-相同方式共享 4.0 国际」许可协议(CC BY-NC-SA 4.0) 进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了