• ICPC+CCPC写题日记~


    要是这个问题再克服不了,就直接g了吧,怨不了别人

    ---------------------------- 2021哈尔滨-------------------------------

    I - Power and Zero

    最近做题总是差这么一点点,但是acm不会接受任何差的这一点点,过不了就是过不了。没什么好说的,加紧练习

    #include
    #define int long long
    #define endl '\n'
    
    using namespace std;
    const int N=1e5+5;
    int n,a[N],bit[55];
    
    void solve()
    {
        for(int i=0; i<=35; i++) bit[i]=0;
        cin>>n;
        int mx=0;
        for(int i=1; i<=n; i++)
        {
            cin>>a[i];
            mx=max(mx,a[i]);
            for(int j=0; j<=31; j++)
            {
                if(((a[i]>>j)&1)==1)
                    bit[j+1]++;
            }
        }
    //    for(int i=32;i>=1;i--)
    //        cout<
    //    cout<
        int g=0;
        for(int i=31; i>=1; i--)
            if(bit[i])
            {
                g=i;
                break;
            }
        while(1)
        {
            int flag=1;
            for(int i=g-1; i>=1; i--)
            {
                while(bit[i]<bit[i+1])
                    flag=0,bit[i]+=2,bit[i+1]-=1;
            }
            if(flag) break;
        }
        cout<<bit[1]<<endl;
    }
    signed main()
    {
        int T;
        cin>>T;
        while(T--)
            solve();
        return 0;
    }
    
    
    
    • 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

    B - Magical Subsequence

    思路:记录每个数字到i位出现的次数。对总和进行枚举2~200.如果本次枚举的需要的数字的位序

    #include
    #define int long long
    #define endl '\n'
    
    using namespace std;
    const int N=1e5+5;
    int n,a[N],sum[105][N];
    void solve()
    {
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            for(int j=1;j<=100;j++)
                sum[j][i]=sum[j][i-1];
            sum[a[i]][i]++;
        }
        int ans=0;
        for(int k=2;k<=200;k++)
        {
            int lim=0,mx=0;
            for(int i=2;i<=n;i++)
            {
                if(k-a[i]<1||k-a[i]>100) continue;
                if(sum[k-a[i]][i-1]-sum[k-a[i]][lim]>0)
                    mx+=2,lim=i;
            }
            ans=max(ans,mx);
        }
        cout<<ans<<endl;
    
    }
    signed main()
    {
        //ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //    int T;cin>>T;
    //    while(T--)
            solve();
        return 0;
    }
    
    
    • 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

    D - Math master

    1.本题会爆longlong,注意开__int128
    2.stoi只在int范围内适用。
    3.一个厉害的技巧:对于一个数字选取任意位的代码实现,有2lx(lx代表长度)种可能。
    4.本题思路:对于数字a的选取有2的lx次方种可能,利用公式xb==ya看能不能找到b,然后去check数字b,看能否消去计算出的b和删去的数字个数是否一致。

    #include
    #define int __int128
    #define endl '\n'
    
    using namespace std;
    const int inf=1e18;
    const int N=1e5+5;
    int read(){	int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-') f=f*-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
    void print(int x){if(x>9) print(x/10ll);putchar(x%10+'0');}
    
    int x,y,lx,ly;
    string sx,sy;
    int vis[105],tag[105];
    
    bool check(int x)
    {
        for(int i=ly-1;i>=0;i--)
        {
            if((sy[i]-'0')==x%10)
                x/=10;
            else
                tag[(sy[i]-'0')]++;
        }
        if(x) return 0;
        for(int i=0;i<=9;i++)
            if(tag[i]!=vis[i]) return 0;
        return 1;
    }
    void solve()
    {
        cin>>sx>>sy;
        x=0,y=0;
        lx=sx.length();
        ly=sy.length();
        for(int i=0;i<lx;i++) x=x*10ll+(sx[i]-'0');
        for(int i=0;i<ly;i++) y=y*10ll+(sy[i]-'0');
        int ansp=x,ansq=y;
        for(int i=0;i<(1<<lx);i++)
        {
            int a=0;
            for(int j=0;j<=9;j++) vis[j]=tag[j]=0;
            for(int j=0;j<lx;j++)
            {
                if((i>>j)&1)
                    a=a*10ll+(int)(sx[j]-'0');
                else
                    vis[(int)(sx[j]-'0')]++;
            }
            if(a==0||a*y%x!=0) continue;
            int b=a*y/x;       //爆long long 注意!!
            if(check(b))
            {
                if(a<ansp)
                {
                    ansp=a;
                    ansq=b;
                }
            }
        }
        print(ansp);cout<<" ";
        print(ansq);cout<<endl;
    }
    signed main()
    {
        //ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
        int T;T=read();
        while(T--)
            solve();
        return 0;
    }
    
    
    • 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
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71

    E. Power and Modulo

    卡住的点,脑瘫简直。数据根本据处理不出来,应该边乘边进行取模

    #include
    #define int long long
    #define endl '\n'
    
    using namespace std;
    const int inf=1e18;
    const int N=1e5+5;
    int n,a[N],fac[105];
    
    void solve()
    {
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i];
        int f1=0,f2=0,m=0,k=1,kk=0;
        for(int i=1;i<=n;i++)
        {
            if(f2) break;
            if(m)
            {
                if(a[i]==k%m) k=k*2%m;
                else f2=1;
            }
            else
            {
                if(a[i]==k)
                {
                    kk=k;k=k*2;continue;
                }
                m=k-a[i];
                f1=1;
                if(m>kk&&m<=k)
                {
                    k=k*2%m;
                    //cout<
                    continue;
                }
                else
                    f2=1;
            }
        }
        if(f2||!f1)
            cout<<-1<<endl;
        else
            cout<<m<<endl;
    }
    signed main()
    {
        ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
        int T;
        cin>>T;
        while(T--)
            solve();
        return 0;
    }
    
    
    • 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

    2019银川站 F题

    F. Function!

    #include 
    #define endl '\n'
    #define int long long
    #define ios (ios::sync_with_stdio(false),cin.tie(0),cout.tie(0))
    #define PII pair<int,int>
    
    using namespace std;
    const int N =7e5+5;
    const int inf=1e18;
    const int mod=998244353;
    const double eps=1e-8;
    int n,a[N];
    int qpow(int x,int y)
    {
        int res=1;
        while(y)
        {
            if(y&1) res=res*x%mod;
            x=x*x%mod;
            y>>=1;
        }
        return res;
    }
    int getinv(int x)
    {
        return qpow(x,mod-2);
    }
    int cal(int x)
    {
        x%=mod;
        return x%mod*(x+1)%mod*(2*x+1)%mod*getinv(6)%mod;
    }
    void solve()
    {
        cin>>n;
        int ans=0;
        for(int i=2; i<=n; i++)
        {
            if(i*i>n)
            {
                n%=mod;
                ans=(ans+(n+1)%mod*(n+i)%mod*(n-i+1)%mod*getinv(2)-((cal(n)-cal(i-1)+mod)%mod)+mod)%mod;
                break;
            }
            int tmp=1;
            for(int l=i,g=0;l<=n;l=tmp,g++)
            {
                tmp=tmp*i;
                if(tmp>n)
                {
                    ans=(ans+i*g%mod*(n-l+1)%mod)%mod;
                    break;
                }
                else
                {
                    ans=(ans+i*g%mod*(tmp-l)%mod)%mod;
                }
            }
        }
        cout<<ans<<endl;
    }
    signed main()
    {
        ios;
    //    int T;
    //    cin>>T;
    //    while(T--)
        solve();
        return 0;
    }
    
    
    • 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
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71

    2019 ccpc 哈尔滨

    I - Interesting Permutation

    #include
    #define int long long
    #define endl '\n'
    
    using namespace std;
    const int N = 2e6+100;
    const int inf=1e18;
    const int mod=1e9+7;
    int n,h[N];
    
    void solve()
    {
        cin>>n;
        for(int i=1;i<=n;i++) cin>>h[i];
        int flag=0;
        for(int i=1;i<=n;i++)
            if(h[i]>=n||h[i]<h[i-1]) flag=1;
        if(flag||h[1]!=0)
        {
            cout<<0<<endl;return;
        }
        int ans=1,cnt=0;
        for(int i=2;i<=n;i++)
        {
            if(h[i]>h[i-1])
            {
                ans=ans*2%mod;
                cnt+=h[i]-h[i-1]-1;
            }
            else if(h[i]==h[i-1])
            {
                ans=ans*cnt%mod;
                cnt--;
            }
        }
        cout<<ans<<endl;
    }
    signed main()
    {
        ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
        int T;cin>>T;
        while(T--)
            solve();
        return 0;
    }
    
    /*
    6
    0 4 4 4 5 5
    */
    
    
    • 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
  • 相关阅读:
    MVC三层架构
    手工编译安装Nginx-1.22.0
    SpringBoot2.7.4整合Redis
    netty怎么解决拆包粘包的问题
    狂神docker
    如何测量带宽使用情况
    AIR780E二次开发点灯(LuatOS)
    MySQL 常用函数
    C++小坑:问号表达式的输出
    2024最新算法:斑翠鸟优化算法(Pied Kingfisher Optimizer ,PKO)求解23个基准函数(提供MATLAB代码)
  • 原文地址:https://blog.csdn.net/weixin_51934288/article/details/127812125