zoukankan      html  css  js  c++  java
  • HDU多校Round 1

    Solved:5

    rank:172

    A.Maximum Multiple

    #include <stdio.h>
    #include <algorithm>
    #include <iostream>
    using namespace std;
    typedef long long ll;
    
    int main()
    {
        int T;
        scanf("%d", &T);
        while(T--)
        {
            int n;
            scanf("%d", &n);
            ll ans = -1;
            if(n % 3 == 0)
            {
                ll x = n / 3;
                ans = max(ans, x * x * x);
            }
            if(n % 4 == 0)
            {
                ll x = n / 4;
                ans = max(ans, x * x * x * 2);
            }
            printf("%lld
    ", ans);
        }
        return 0;
    }
    View Code

    B.Balanced Sequence

    #include <stdio.h>
    #include <algorithm>
    #include <iostream>
    #include <string.h>
    using namespace std;
    
    char s[100005];
    struct node
    {
        int l, r;
    }E[100005];
    
    bool cmp(node A, node B)
    {
        int tmp1 = min(A.l, B.r);
        int tmp2 = min(A.r, B.l);
        if(tmp1 == tmp2) return A.r < B.r;
        else return tmp1 > tmp2;
    }
    
    int main()
    {
        int T;
        scanf("%d", &T);
        while(T--)
        {
            int ans = 0; int cnt = 0;
            int suml = 0, sumr = 0;
            int n;
            scanf("%d", &n);
            for(int i = 1; i <= n; i++)
            {
                scanf("%s", s);
                int len = strlen(s);
    
                int cnl = 0, cnr = 0;
                for(int j = 0; j < len; j++)
                {
                    if(s[j] == '(') cnl++;
                    else
                    {
                        if(cnl)
                        {
                            cnl--;
                            ans += 2;
                        }
                        else cnr++;
                    }
                }
                if(cnl == 0) sumr += cnr;
                else if(cnr == 0) suml += cnl;
                else
                {
                    cnt++;
                    E[cnt].l = cnl;
                    E[cnt].r = cnr;
                }
            }
            sort(E + 1, E + 1 + cnt, cmp);
    
            for(int i = 1; i <= cnt; i++)
            {
                if(suml >= E[i].r)
                {
                    ans += E[i].r * 2;
                    suml -= E[i].r;
                    suml += E[i].l;
                }
                else
                {
                    ans += suml * 2;
                    suml = E[i].l;
                }
            }
            ans += min(suml, sumr) * 2;
            printf("%d
    ", ans);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    uniapp请求拦截
    stellar视差插件
    fullpage全屏插件应用
    fullpage全屏插件简介
    WdatePicker日期插件
    Ueditor富文本编辑器
    layer弹出层
    验证码绘制
    Ajax跨域访问
    JQuery封装的ajax方法
  • 原文地址:https://www.cnblogs.com/lwqq3/p/9357295.html
Copyright © 2011-2022 走看看