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

2019 Multi-University Training Contest 6

时间:2019-08-07 18:50:13      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:pid   and   href   real   scan   operator   mes   mile   salt   

Salty Fish

Support or Not

Three Investigators

Milk Candy

Ridiculous Netizens

Stay Real

#include <bits/stdc++.h>
 
using namespace std;
 
const int maxn=100010;
typedef long long ll;
struct node
{
    ll val,id;
    node(int _val,int _id):val(_val),id(_id) {};
    bool operator < (const node &b)const
    {
        return val<b.val;
    }
};
 
ll h[maxn],vis[maxn*2],n,suma,sumb,flag,fa;
priority_queue<node>q;
 
int main()
{
    int T;
    scanf("%d",&T);
    while (T--)
    {
        scanf("%lld",&n);
        for (int i=1; i<=n; i++)
        {
            vis[i]=1;
        }
        for (int i=1; i<=n; i++)
        {
            scanf("%lld",&h[i]);
            if (vis[i<<1]==0&&vis[i<<1|1]==0)
            {
                q.push(node(h[i],i));
            }
        }
        suma=sumb=0;
        flag=1;
        while (!q.empty())
        {
            node tmp=q.top();
            q.pop();
            if (flag)
            {
                suma+=tmp.val;
            }
            else
            {
                sumb+=tmp.val;
            }
            vis[tmp.id]=0;
            flag^=1;
            fa=tmp.id>>1;
            if (vis[fa<<1]==0&&vis[fa<<1|1]==0&&fa!=0)
            {
                q.push(node(h[fa],fa));
            }
        }
        printf("%lld %lld\n",suma,sumb);
    }
    return 0;
}

TDL

Snowy Smile

Faraway

Nonsense Time

Speed Dog

11 Dimensions

 

2019 Multi-University Training Contest 6

标签:pid   and   href   real   scan   operator   mes   mile   salt   

原文地址:https://www.cnblogs.com/Accpted/p/11316849.html

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