• 湖南大学第十五届程序设计竞赛


    B Kuangyeye’s Resistance

    这题需要一定的物理知识,将电阻串并联的关系理清,在加一个递推式即可。
    在这里插入图片描述
    在这里插入图片描述

    #include<bits/stdc++.h>
    using namespace std;
    #define maxn 100005
    #define ll long long
     
    ll n,R,p;
    ll a[maxn],b[maxn];
    ll poww(ll a,ll b){
        ll ans=1,base=a%p;
        while(b!=0){
            if(b&1!=0)ans=(ans*base)%p;
            base=(base*base)%p;
            b>>=1;
        }
        return ans%p;
    }
     
    int main()
    {
        scanf("%lld %lld %lld",&n,&R,&p);
        a[1]=1,b[1]=1;
        for(int i=2;i<=n;i++)
            a[i]=(2+a[i-1])*poww(3+a[i-1],p-2)%p;
        printf("%lld
    ",a[n]*R%p);
        return 0;
    }

    C One Piece

    在这里插入图片描述
    在这里插入图片描述

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    const int maxn = 1e5+7;
    ll t,n;
    ll lowbit(ll x){
        return (-x) & x;
    }
    int main(){
        int t ;
        scanf("%lld", &t) ;
        while(t--){
            scanf("%lld", &n);
            int cnt = 0;
            if(n < 0) n += (1ll<<32);
            for(ll i = n ; i > 0 ; i -= lowbit(i)) cnt ++;
            cout << cnt << endl;
        }
        return 0;
    }

    D Kth height

    这题主要是二分套二分这个思路不好想,找出两个队伍中第k矮的。
    在这里插入图片描述
    在这里插入图片描述

    #include<bits/stdc++.h>
    using namespace std;
    #define maxn 300005
    #define ll long long
     
    int n,m;
    int s1[maxn],s2[maxn];
    int a,b,c,d;
    int main()
    {
        while(~scanf("%d",&n)){
            for(int i=1;i<=n;i++)
                scanf("%d",&s1[i]);
            for(int i=1;i<=n;i++)
                scanf("%d",&s2[i]);
            scanf("%d",&m);
            while(m--){
                scanf("%d %d %d %d",&a,&b,&c,&d);
                if(a==1)s1[b]=c;
                else s2[b]=c;
                int l=0,r=d,ans;
                while(l<=r){
                    int mid=(l+r)/2;
                    int t=upper_bound(s2+1,s2+n+1,s1[mid])-s2-1;
                    if(mid+t<=d){
                        l=mid+1;
                        ans=mid;
                    }
                    else if(mid+t>d)r=mid-1;
                }
                int maxx=max(s1[ans],s2[d-ans]);
                printf("%d
    ",maxx);
            }
        }
        return 0;
    }

    F Cards with Numbers

    这题虽然看上去简单,但是由于数据的缘故,空间和时间的复杂度要求比较高,自然就不能用常规方法来解,这里我们对数据进行离线处理,二分一下就ok了。
    在这里插入图片描述
    在这里插入图片描述

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<queue>
    #include<cstdlib>
    #include<cmath>
    #include<stack>
    #include<map>
    #include<string>
    #include<vector>
    #include<algorithm>
    using namespace std;
    #define ll long long
    #define INF 0x3f3f3f3f
    #define ull unsigned long long
    #define endl '
    '
    const double pi = acos(-1);
    const int maxn = 1e6 + 10;
    const int maxm = 2e7 + 10;
    const ll mod = 998244353;
    int t, tt, n, m, op;
    struct node{
        int x;
        int y;
    }a[maxn], b[maxn];
    bool cmp(node aa, node bb){
        return aa.x < bb.x;
    }
    int main(){
        scanf("%d", &n);
        for(int i = 1 ; i <= n ; ++ i){
            scanf("%d %d", &op, &m);
            if(op == 0) a[++t].x = m, a[t].y=i;
            if(op == 1) b[++tt].x = m, b[tt].y=i;
        }
        sort(a + 1, a + 1 + t, cmp);
        for(int i = 1 ; i <= tt ; ++ i){
            int l = 1, r = t;
            while(l <= r){
                int mid = (l + r) >> 1;
                if(a[mid].x==b[i].x){
                    l = mid;break;
                }
                else if(a[mid].x < b[i].x) l = mid + 1;
                else r = mid - 1;
            }
            int p = l;
            if(a[p].x==b[i].x&&a[p].y<b[i].y) cout << "yes" <<endl;
            else cout << "no" <<endl;
        }
        return 0;
    }

    G Longest Palindrome Substring

    在这里插入图片描述
    在这里插入图片描述

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<queue>
    #include<cstdlib>
    #include<cmath>
    #include<stack>
    #include<map>
    #include<string>
    #include<vector>
    #include<algorithm>
    using namespace std;
    #define ll long long
    #define INF 0x3f3f3f3f
    #define ull unsigned long long
    #define endl '
    '
    const double pi = acos(-1);
    const int maxn = 1e5 + 10;
    const int maxm = 2e7 + 10;
    const ll mod = 998244353;
    int n, flag;
    char s[maxn];
    int main(){
        scanf("%d", &n);
        scanf("%s", s);
        int len = strlen(s);
        for(int i = 1 ; i < len ; ++ i){
            if(s[i]==s[i-1]){
                flag = 1;
                break;
            }
        }
        for(int i = 1 ; i < len - 1 ; ++ i){
            if(s[i+1]==s[i-1]){
                flag = 1;
                break;
            }
        }
        if(flag) cout << "YES";
        else cout << "NO";
        return 0;
    }

    I Algorithm Choosing Mushrooms

    贪心

    在这里插入图片描述
    在这里插入图片描述

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<queue>
    #include<cstdlib>
    #include<cmath>
    #include<stack>
    #include<map>
    #include<string>
    #include<vector>
    #include<algorithm>
    using namespace std;
    #define ll long long
    #define INF 0x3f3f3f3f
    #define ull unsigned long long
    #define endl '
    '
    const double pi = acos(-1);
    const int maxn = 2e5 + 10;
    const int maxm = 2e7 + 10;
    const ll mod = 998244353;
    int n, m;
    ll a[maxn], m1, m2, p[maxn];
    struct node{
        ll sum, id;
    }s[maxn];
    bool cmp(node a, node b){
        return a.sum == b.sum ? a.id < b.id : a.sum < b.sum;
    }
    int main(){
        scanf("%d %d", &n, &m);
        for(int i = 1 ; i <= n ; ++ i){
            scanf("%d", &a[i]);
            s[i].sum = (s[i-1].sum + a[i]) % m;
            p[i] = p[i-1]+a[i];
            s[i].id = i;
        }
        //for(int i = 1 ; i <= n ; ++ i) cout << s[i].sss << ' ';
        //cout << endl;
        sort(s + 1, s + 1 + n, cmp);
     
        int t = 1;
        for(int i = 1 ; i <= n ; ++ i){
            if(s[i].sum!=s[t].sum){
                int r = s[i-1].id, l = s[t].id;
                //cout << l << ' ' << r << endl;
                m1 = max(p[r]-p[l], m1);
                //cout << s[r].sss-s[l].sss << endl;
                m2 = max(m2, (ll)(r-l));
                t = i;
            }
        }
        //cout << t << endl;
        //cout << s[t-1].sss << ' ' << s[n].sss << endl;
        int r = s[n].id, l = s[t].id;
        m1 = max(p[r]-p[l], m1);
        m2 = max(m2, (ll)(r-l));
     
        cout << m1 << ' ' << m2;
        return 0;
    }
    希望用自己的努力为自己赢得荣誉。
  • 相关阅读:
    关于OPC的研究1]c# opc client源码调试和学习笔记
    分治算法
    递归算法
    Linux 课程笔记 Nginx深入应用实践
    Linux课程笔记 Nginx介绍
    Linux课程笔记 Apache补充
    Linux课程笔记 Apache服务Forbidden 403故障分析
    Linux课程笔记 Apache的优化
    Linux课程笔记 Apache常用模块的介绍
    Linux课程笔记 Apache的介绍与安装
  • 原文地址:https://www.cnblogs.com/Mmasker/p/11917480.html
Copyright © 2020-2023  润新知