码迷,mamicode.com
首页 > 其他好文 > 详细

<hdu多校round 1>

时间:2018-07-23 23:40:30      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:include   tmp   struct   stdio.h   stream   图片   type   mes   opened   

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\n", 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\n", ans);
    }
    return 0;
}
View Code

 

<hdu多校round 1>

标签:include   tmp   struct   stdio.h   stream   图片   type   mes   opened   

原文地址:https://www.cnblogs.com/lwqq3/p/9357295.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!