NOIP(第26届)--2020(CSP-S2)2--提高组--复赛--试题与答案

2022-07-05 已有0人阅读 作者: IT航班

中小学编程红宝书.zip

 

第1题(day1):儒略日

1、说明

A、试题类型:

       代码题。

 

B、算法模型:

       一些简单算法整合。

 

C、试题说明:

       暴力求解。

分类讨论。

每一段都数据验证。

 

2、代码

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

#define I int

#define ll long long

#define F(i,a,b) for(I i=a;i<=b;i++)

#define Fd(i,a,b) for(I i=a;i>=b;i--)

#define mem(a,b) memset(a,b,sizeof a)

using namespace std;

 

ll T,r,d,m,y;

I bc,a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

 

I main()

{

       freopen("julian.in","r",stdin);

       freopen("julian.out","w",stdout);

       scanf("%lld",&T);

       I tot=0;

       while(T--)

       {

              if(++tot==21)

              {

                     tot++,tot--;

              }

              scanf("%lld",&r);

              bc=(r<1721424);y=4713,m=1,d=1;

              if(r<1721424)

              {

                     y-=(r/1461)*4;

                     r%=1461;

                     while(r>=365+(y%4==1))

                     {

                            r-=365+(y%4==1);y--;

                     }

                     if(!y) y=1;

                     while(r)

                     {

                            if(m!=2&&r>=a[m])

                            {

                                   r-=a[m];m++;

                            }

                            else if(m==2&&r>=a[m]+(y%4==1))

                            {

                                   r-=a[m]+(y%4==1);m++;

                            }

                            else

                            {

                                   d+=r;r=0;break;

                            }

                     }

              }

              else

              {

                     r-=1721424;

                     if(r<=577736)

                     {

                            y=m=d=1;

                            y+=(r/1461)*4;

                            r%=1461;

                            while(r>=365+(y%4==0))

                            {

                                   r-=365+(y%4==0);y++;

                            }

                            while(r)

                            {

                                   if(m!=2&&r>=a[m])

                                   {

                                          r-=a[m];m++;

                                   }

                                   else if(m==2&&r>=a[m]+(y%4==0))

                                   {

                                          r-=a[m]+(y%4==0);m++;

                                   }

                                   else

                                   {

                                          d+=r;r=0;

                                          break;

                                   }

                            }

                     }

                     else

                     {

                            y=1582,m=10,d=15;

                            r-=577737;

                            if(r<78)

                            {

                                   if(r<=16)

                                   {

                                          d+=r;

                                   }

                                   else

                                   {

                                          r-=17;

                                          m=11,d=1;

                                          while(r)

                                          {

                                                 if(m!=2&&r>=a[m])

                                                 {

                                                        r-=a[m];m++;

                                                 }

                                                 else if(m==2&&r>=a[m]+(((y%4==0)&&(y%100>0))||(y%400==0)))

                                                 {

                                                        r-=a[m]+(((y%4==0)&&(y%100>0))||(y%400==0));m++;

                                                 }

                                                 else

                                                 {

                                                        d+=r;r=0;

                                                        break;

                                                 }

                                                 if(m>12)

                                                        m=1;

                                          }

                                   }

                            }

                            else

                            {

                                   r-=78;

                                   y=1583,m=d=1;

                                   y+=(r/584388)*1600;

                                   r%=584388;

                                   while(r>=365+((((y)%4==0)&&((y)%100>0))||((y)%400==0)))

                                   {

                                          r-=365+((((y)%4==0)&&((y)%100>0))||((y)%400==0));

                                          y++;

                                   }

                                   while(r)

                                   {

                                          if(m!=2&&r>=a[m])

                                          {

                                                 r-=a[m];m++;

                                          }

                                         else if(m==2&&r>=a[m]+(((y%4==0)&&(y%100>0))||(y%400==0)))

                                          {

                                                 r-=a[m]+(((y%4==0)&&(y%100>0))||(y%400==0));m++;

                                          }

                                          else

                                          {

                                                 d+=r;r=0;

                                                 break;

                                          }

                                   }

                            }

                     }

              }

              if(!bc)

                     printf("%lld %lld %lld\n",d,m,y);

              else

                     printf("%lld %lld %lld BC\n",d,m,y);

       }

       return 0;

}

第2题(day2):动物园

1、说明

A、试题类型:

       模拟题。

 

B、算法模型:

       基本逻辑推演。

 

C、试题说明:

       unsigned long long应用。

2、代码

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

#define I int

#define ll unsigned long long

#define F(i,a,b) for(I i=a;i<=b;i++)

#define Fd(i,a,b) for(I i=a;i>=b;i--)

#define mem(a,b) memset(a,b,sizeof a)

using namespace std;

 

ll n,m,c,k,x,now,p,q,ans,s[66];

I a[21]={20,6,1,6,1,5,5,9,0,7,3,7,0,4,4,7,6,4,4,8,1},bz;

 

I main()

{

       freopen("zoo.in","r",stdin);

       freopen("zoo.out","w",stdout);

      

       scanf("%llu%llu%llu%llu",&n,&m,&c,&k);

      

       F(i,1,n)

       {

              scanf("%llu",&x);

              now|=x;

       }

      

       F(i,0,k-1) s[i]=2;

       F(i,1,m){

              scanf("%llu%llu",&p,&q);

              if(!((now>>p)&1)) s[p]=1;

       }

      

       ans=bz=1;

       F(i,0,k-1) ans=ans*s[i];

       F(i,0,k-1)

              if(s[i]!=2)

              {

                     bz=0;break;

              }

              if(k==64&&bz)

              {

                     a[1]-=n;

                     F(i,1,a[0]){

                            while(a[i]<0)

                            {

                                   a[i]+=10;

                                   a[i+1]--;

                            }

                     }

                     while(!a[a[0]])

                            a[0]--;

                     Fd(i,a[0],1)

                            printf("%d",a[i]);

                     return 0;

              }

              printf("%llu\n",ans-n);

              return 0;

}

第3题(day3):函数调用

1、说明

A、试题类型:

       混合题。

 

B、算法模型:

       数据结构 + 算法 + 思想。

 

C、试题说明:

       暴力模拟。最小闭合子图、子树。拓扑排序。

2、代码

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

#define I int

#define ll long long

#define F(i,a,b) for(register I i=a;i<=b;i++)

#define Fd(i,a,b) for(register I i=a;i>=b;i--)

#define N 100005

#define M 1000004

#define mo 998244353

using namespace std;

 

I n,m,a[N],f[N],op[N],b[N],v[N],c[N],q[M],r,x,s;

I t[M<<1],nx[M<<1],ls[M],d[M],tot,p;

 

I R(I &x)

{

       x=0;

       char c=getchar();

       while(c<'0'||c>'9')

              c=getchar();

       while(c>='0'&&c<='9')

       {

              x=x*10+c-'0';

              c=getchar();

       }

       return x;

}

 

void add(I x,I y)

{

       d[t[++tot]=y]++,nx[tot]=ls[x],ls[x]=tot;

}

 

I main()

{

       freopen("call.in","r",stdin);

       freopen("call.out","w",stdout);

      

       R(n);

       F(i,1,n) R(a[i]);

       R(m);

       F(i,1,m)

       {

              R(op[i]);

              if(op[i]==1)

              {

                     R(b[i]),R(v[i]);

              }

              else if(op[i]==2)

                     R(v[i]);

              else

              {

                     R(p);

                     while(p--)

                            add(i,R(x));

              }

       }

      

       R(p);

       F(i,1,p) add(0,R(x));

      

       F(i,0,m)

              if(!d[i]) q[++r]=i;//注意n和m千万不要打反,不然可能少了那么40分左右

             

              F(i,1,r)

              {

                     x=q[i];

                     for(I k=ls[x];k;k=nx[k]) i

                            f(!--d[t[k]])

                            q[++r]=t[k];

              }

              Fd(i,r,1)

              {

                     x=q[i];

                     d[x]=op[x]==2?v[x]:1;

                     for(I k=ls[x];k;k=nx[k])

                            d[x]=(ll)d[x]*d[t[k]]%mo;

              }

             

              F(i,1,n) a[i]=(ll)a[i]*d[0]%mo;

              f[0]=1;

             

              F(i,1,r)

              {

                     x=q[i];

                     s=1;

                     for(I k=ls[x];k;k=nx[k])

                     {

                            f[t[k]]=(ll)(f[t[k]]+(ll)s*f[x]%mo)%mo;//注意这个加法操作可能有多个父亲,

                            //从每个父亲走到这里都加了一遍,所以是所有父亲的后继积分别乘以这个加法操作再求和

                            s=(ll)s*d[t[k]]%mo;

                     }

                    

                     if(op[x]==1)

                            a[b[x]]=(ll)(a[b[x]]+(ll)f[x]*v[x]%mo)%mo;

              }

             

              F(i,1,n) printf("%d ",a[i]);

             

              return 0;

}

 

第1题(day2):贪吃蛇

1、说明

A、试题类型:

       混合题。

 

B、算法模型:

       双端队列。

 

C、试题说明:

       队列,递归,模拟,双端队列。

 

 

2、代码

#include<cstdio>

#include<cstring>

#include<algorithm>

#define I int

#define F(i,a,b) for(I i=a;i<=b;i++)

#define mem(a,b) memset(a,b,sizeof a)

#define N 1000005

using namespace std;

 

I T,n,x,y,z,l,r,ans,cnt,bz;

struct node

{

       I v,id;

}a[N],b[N],now,mx,mn;

 

I R(I &x)

{

       x=0;I w=1;char c=getchar();

      

       while(c<'0'||c>'9')

       {

              if(c=='-') w=-1;c=getchar();

       }

      

       while(c>='0'&&c<='9')

       {

              x=x*10+c-'0';c=getchar();

       }

      

       return x*=w;

}

 

I cmp(node x,node y)

{

       return x.v>y.v||x.v==y.v&&x.id>y.id;

}//储存编号用于比较大小

 

void work()

{

       x=l=1,y=n,r=0;

       mem(b,0);

       while(1)

       {

              if(y-x+r-l==0)

              {

                     ans=1;

                     break;

              }

             

              mn=a[x++];

              mx=(x>y||l<=r&&cmp(b[l],a[y]))?b[l++]:a[y--];

              now=node{mx.v-mn.v,mx.id};

             

              if(x>y||cmp(a[x],now))

              {

                     ans=y-x+r-l+4;/*当前蛇先不吃,再看看能不能吃*/cnt=1;//cnt记录被吃的蛇的条数

                     while(1)

                     {

                            cnt++;

                            if(y-x+r-l==-1)

                            {

                                   ans-=cnt&1;

                                   break;

                            }

                           

                            mx=(x>y||l<=r&&cmp(b[l],a[y]))?b[l++]:a[y--];

                            now=node{mx.v-now.v,mx.id};

                            if(x<=y&&cmp(now,a[x])||l<=r&&cmp(now,b[r]))

                            {

                                   ans-=cnt&1;

                                   break;

                            }

                     }

                     break;

              }

              else b[++r]=now;

       }

       printf("%d\n",ans);

      

}

 

I main()

{

       freopen("snakes.in","r",stdin);

       freopen("snakes.out","w",stdout);

      

       R(T),R(n);

       F(i,1,n) a[i]=node{R(x),i};

       work();

      

       F(tm,2,T)

       {

              R(z);

              while(z--)

                     a[R(x)].v=R(y);

              work();

       }

       return 0;

}


 

IT航班提供:教辅资料、课程视频、课程书籍、竞赛辅导、少儿编程指导、课程采购、加盟、少儿编程资料、少儿编程课程、保送生、特长生、加分、中小学计算机教育、中小学信息学、竞赛、中小学信息学课程、人工智能、中小学编程加盟、少儿编程加盟、品牌加盟、技术加盟、技术指导、课程加盟、师资培训、中小学编程教辅资料、中小学编程教师培训、少儿编程教学书籍、少儿编程视频、教学书籍、教师培训、教学视频、CSP-J/S、中小学信息学课程服务、竞赛指导、课程提供、国内外计算机中小学计算机竞赛、信息学竞赛、信息学课程提供商、信息学奥林匹克。

      

 

IT航班支持----中小学编程比赛汇总:

 

第一部分:国内比赛(IT航班支持)   

1、软件能力认证(CSP-JS) 

2、全国青少年信息学奥林匹克联赛(NOIP)    

3、全国青少年信息学奥林匹克竞赛(NOI)

4、中国青少年………………………  

5、………………………创新挑战赛  

6、全国青少年………………………  

7、………………………

8、 恩欧希教育信息化发明创新奖  

9、世界机器人大赛(WRC) 

10、………………………大赛    

11、少………………………智能教育成果展示大赛 

12、“明天小小科学家”奖励活动

13、………………………    

14、………………………    

15、国际信息学……………………… 

16、………………………    

 

第二部分:国际比赛(IT航班支持)   

17、………………………    

18、国际………………………    

19、………………………

20、美国信息学……………………… 

21、加拿大……………………… 

22、官方邀请赛 (CCO)     

23、国际计算思维………………………    

24、美国计算机……………………… 

25、澳大利亚………………………    

 

第三部分:企业比赛(IT航班支持)   

26、微软MTA    

27、………………………挑战赛 

28、………………………科学奖 

29、………………………学奖    

30、………………………创新挑战赛 

31、………………………挑战赛 

32、………………………芯计算机表演赛 

33、………………………大赛    

 

第四部分:Scratch相关竞赛(IT航班支持)    

34、全国中小学生电脑制作大赛     

35、………………………    

36、………………………    

37、………………………    

 

第五部分:其它(IT航班支持)   

38、NOI夏令营  

39、NOI冬令营(NOIWC)  

40、全国青少年……………………… 

41、国际青少年………………………

 

 

联系方式:

A、官方网址:

http://www.itflight.net


B、微信公众号:

添加微信,获取资料。

image.png

 



关注公众号,获取动态。

image.png