2022年蓝桥杯省赛 C++ B组

九进制转十进制

#include<bits/stdc++.h>
using namespace std;
int main()
{
	cout<<1478<<endl;
	return 0;
}

顺子日期

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int months[]={0,31,28,31,30,31,30,
                31,31,30,31,30,31};
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
     
    int year=2022,month=1,day=1;
    int ans=0;
    for(int i=1;i<=365;i++)
    {
        char ch[9]={0};
        sprintf(ch,"%04d%02d%02d",year,month,day);
        bool flag=false;
        for(int j=0;j<6;j++)
        {
            if(ch[j+1]==ch[j]+1&&ch[j+2]==ch[j]+2)
            {
                flag=true;
                break;
                //ans++;不能这样,可能会多算
            }
        }
        if(flag==true)
            ans++;
        day++;
        if(day>months[month])
        {
            day=1;
            month++;
        }
    }
    cout<<ans;
     
     
}

刷题统计

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    LL n;
    LL a,b;
    cin>>a>>b>>n;
    LL w =5*a+2*b;
    LL week_count=n/w;
    LL yu_n = n%w;
    LL day_c=0;
    if(yu_n==0)
    {
        cout<<week_count*7<<endl;
        return 0;
    }
    for(int i=1;i<=7;i++)
    {
        if(i==6||i==7)
            yu_n-=b;
        else
            yu_n-=a;
        day_c++;
        if(yu_n<=0)
            break;
         
    }
    cout<<day_c+week_count*7<<endl;
    return 0;
}

修剪灌木

#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        if(i<=n/2)
        {
            cout<<2*(n-i)<<endl;
        }
        else
        {
            cout<<2*(i-1)<<endl;
             
        }
    }
    return 0;
}

X进制减法

#include<bits/stdc++.h>
using namespace std;
int jin_zhi[100000],A[100000],B[100000];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
     
    int N;
    cin>>N;
    int Ma,Mb;
    cin>>Ma;
    for(int i=Ma-1;i>=0;i--)
        cin>>A[i];
    cin>>Mb;
    for(int i=Mb-1;i>=0;i--)
        cin>>B[i];
    int W=max(Ma,Mb);//W表示最多几位
 
    bool exist_N=false;
    for(int i=0;i<W;i++)
    {
        jin_zhi[i]=max(A[i],B[i])+1;
        if(jin_zhi[i]<2)
            jin_zhi[i]=2;
        if(jin_zhi[i]==N)
            exist_N=true;
    }
     
    if(exist_N==false)
        jin_zhi[W-1]=N;
    long long s=1,result=0;
    for(int i=0;i<W;i++)
    {
          
        result=(result+(A[i]-B[i])*s)%1000000007;
        s=(s*jin_zhi[i])%1000000007;//s也要取余,哭了
    }
    cout<<result;
 
}

统计子矩阵

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=510;
int n,m,k;
int s[N][N];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            cin>>s[i][j];
            s[i][j]+=s[i-1][j];
        }
    ll res=0;
    for(int i=1;i<=n;i++)
        for(int j=i;j<=n;j++)
            for(int l=1,r=1,sum=0;r<=m;r++)
            {
                sum+=s[j][r]-s[i-1][r];
                while(sum>k)
                {
                    sum-=s[j][l]-s[i-1][l];
                    l=l+1;
                }
                res +=r-l+1;
            }
    cout<<res;
    return 0;
}

积木画

#include<bits/stdc++.h>
using namespace std;
const int N=1e7+10,MOD=1e9+7;
 
int n;
int g[4][4]={
    {1,1,1,1},
    {0,0,1,1},
    {0,1,0,1},
    {1,0,0,0},
     
};  
//f[i][j]表示已经操作完前i-1列且第i列的状态为0的所有方案的集合
int f[2][4];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    f[1][0]=1;
    for(int i=1;i<=n;i++)
    {
        memset(f[i+1&1],0,sizeof(f[0]));
        for(int j=0;j<4;j++)
            for(int k=0;k<4;k++)
                if(g[j][k])
                    f[i+1 & 1][k]=(f[i+1 & 1][k]+f[i & 1][j])%MOD;
    }
    cout<<f[n+1 & 1][0];
     
     
    return 0;
}

扫雷

#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;
const int N=50010,M = 999997;
int n,m;
 
struct Circle
{
    int x,y,r;
}cir[N];
LL h[M];//哈希表
int id[M];//
 
bool st[M];//雷是否爆
//将x,y转成long long
LL get_key(int x,int y)//根据坐标求哈希值
{
    return x*1000000001ll+y;//整数后加ll会把整数转longlong
}
//将long long转成999997以内
int find(int x,int y)
{
    LL key=get_key(x,y);
    int t = (key % M+M)%M;//转成非负,下标
     
    while(h[t]!=-1&&h[t]!=key)
        if(++t==M)
            t=0;
    return t;
}
int sqr(int x)
{
    return x*x;
}
void dfs(int x,int y,int r)
{
    st[find(x,y)]=true;
    for(int i=x-r;i<=x+r;i++)
            for(int j=y-r;j<=y+r;j++)
                if(sqr(i-x)+sqr(j-y)<=sqr(r))
                {
                     
                    int t=find(i,j);
                    if(id[t]&&!st[t])//如果有雷并且这个雷被搜过
                    {
                        dfs(i,j,cir[id[t]].r);
                    }
                         
                }
                 
             
}
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
     
    memset(h,-1,sizeof(h));
     
     
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        //cin>>cir[i].x>>cir[i].y>>cir[i].r;
        int x,y,r;
        cin>>x>>y>>r;
        cir[i]={x,y,r};
         
        int t=find(x,y);//求哈希值
        if(h[t]==-1)
            h[t]=get_key(x,y);
        if(!id[t]||cir[id[t]].r<r)
            id[t]=i;
    }
    while(m--)
    {
        int x,y,r;
        cin>>x>>y>>r;
        //枚举火箭周围的所有点
        for(int i=x-r;i<=x+r;i++)
            for(int j=y-r;j<=y+r;j++)
            {
                if(sqr(i-x)+sqr(j-y)<=sqr(r))
                {
                    int t=find(i,j);
                    if(id[t]&&!st[t])//如果点存在且这个点未被搜过,则搜这个点
                        dfs(i,j,cir[id[t]].r);
                }
            }
    }
    int res=0;
    for(int i=1;i<=n;i++)
        if(st[find(cir[i].x,cir[i].y)])
            res++;
    cout<<res;
         
     
    return 0;
}
  

李白打酒加强版

#include<bits/stdc++.h>
using namespace std;
const int N=103,M=103,MOD=1000000007;
int f[N][M][M];
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
     
    cin>>t;
    pair<int ,int> p[t];
    for(int i=0;i<t;i++)
    {
        int x,y;
        cin>>x>>y;
        p[i]={x,y};
    }
    for(int tt=0;tt<t;tt++)
    {
        int n,m;
        n=p[tt].first;
        m=p[tt].second;
        memset(f,0,sizeof(f));
        f[0][0][2]=1;
        for(int i=0;i<=n;i++)
            for(int j=0;j<=m;j++)
                for(int k=0;k<=m;k++)
                {
                    if(k%2==0&&i>=1)
                        f[i][j][k]=(f[i][j][k]+f[i-1][j][k/2])%MOD;
                    if(j>=1)
                        f[i][j][k]=(f[i][j][k]+f[i][j-1][k+1])%MOD;
                }
        cout<<f[n][m-1][1]<<endl;
    }
    return 0;
}

砍竹子

#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;
 
const int N=200009,M=7;
int n,layer;
LL f[N][M];
 
int main()
{
     
    cin>>n;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        LL temp[7];
        int top=0;
        LL h;
        cin>>h;
        while(h>1) temp[top++]=h,h=sqrt(h/2+1);
        layer=max(top,layer);
        ans+=top;
        for(int j=0;top>0;top--,j++)
        {
            f[i][j]=temp[top-1];
        }
    }
 
    for(int i=0;i<layer;i++)
        for(int j=1;j<n;j++)
        {
            if((f[j][i]==f[j-1][i])&&f[j][i])
                ans--;
        }
    cout<<ans<<endl;
     
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值