2019 Multi-University Training Contest 6

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

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

时间: 2024-11-06 09:45:22

2019 Multi-University Training Contest 6的相关文章

2019 HDOJ Multi-University Training Contest Stage 8(杭电多校)

中规中矩的一场. 题目链接:http://acm.hdu.edu.cn/contests/contest_show.php?cid=855 C: 定义函数f(d,k)为数字d在数字k中出现的次数.给定d和x,找到尽量大的k使得k<=x且f(d,k)==k. 很诡异的一题,最好的做法仍然是打表找规律.题解给了一个很神奇的结论:满足条件的k<1011且k的分布非常稀疏. 1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* defin

2019 HDOJ Multi-University Training Contest Stage 10(杭电多校)

最后一场多校打得一般般. 题目链接:http://acm.hdu.edu.cn/contests/contest_show.php?cid=857 C: E: I: BFS水题. 1 /* Codeforces Contest 2019_mutc_10 2 * Problem I 3 * Au: SJoshua 4 */ 5 #include <queue> 6 #include <cstdio> 7 #include <vector> 8 #include <s

2019 HDOJ Multi-University Training Contest Stage 2(杭电多校)

服务器时不时爆炸,有点难受. 题目链接:http://acm.hdu.edu.cn/userloginex.php?cid=849 A: 神仙题.不可做题. B: dp. C: 推式子题. D: 边分治. E: 可以数学推理的题.但是显然打表更快找出规律.对打出来的结果做两次差分即可. 1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou doubl

2019 HDOJ Multi-University Training Contest Stage 4(杭电多校)

很抱歉过了这么多天才补这场,最近真的挺忙的…… 出题人是朝鲜的(目测是金策工业?),挺难. 题目链接:http://acm.hdu.edu.cn/contests/contest_show.php?cid=851 A: 签到题. 对于当前的点,若其编号为偶数,则可与1相连使得边权贡献为0.否则从低位向高位找当前点编号的二进制表示的第一个0,使这个0变为1,其他位置变为0并检查新的数字是否小于等于n.若小于等于n则贡献为0,反之贡献为1. 1 /* basic header */ 2 #inclu

2019 Nowcoder Multi-University Training Contest 1 H-XOR

由于每个元素贡献是线性的,那么等价于求每个元素出现在多少个异或和为$0$的子集内.因为是任意元素可以去异或,那么自然想到线性基.先对整个集合A求一遍线性基,设为$R$,假设$R$中元素个数为$r$,那么任取一个不在$R$内的元素,$R$中肯定存在一种取法能和这个元素异或和为$0$.同理,取定一个不在$R$内的元素,再随便取另外任意个不在$R$内的元素,$R$内仍然存在一种取法使得这个异或和为$0$.那么每个不在$R$内的元素包含在$2^{n - r - 1}$个集合内(其他不在$R$内的元素可以

HDU校赛 | 2019 Multi-University Training Contest 3

2019 Multi-University Training Contest 3 http://acm.hdu.edu.cn/contests/contest_show.php?cid=850 1004. Distribution of books 考虑二分答案,设当前二分出来的是\(x\). 设\(f_i\)表示前\(i\)个能分成最多的段数,使得每一段和都\(\leqslant x\). 转移显然,枚举一个\(j\),若\(s_i-s_j\leqslant x\)则转移,\(s_i\)表示前

[最短路,最大流最小割定理] 2019 Multi-University Training Contest 1 Path

题目:http://acm.hdu.edu.cn/showproblem.php?pid=6582 Path Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 3747    Accepted Submission(s): 1075 Problem Description Years later, Jerry fell in love

HDU4888 Redraw Beautiful Drawings(2014 Multi-University Training Contest 3)

Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Alice and Bob are playing together. Alice is crazy about art and she has visited many museums around the world. She has

HDU 2018 Multi-University Training Contest 3 Problem A. Ascending Rating 【单调队列优化】

任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6319 Problem A. Ascending Rating Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 5943    Accepted Submission(s): 2004 Problem Description Before

2014 Multi-University Training Contest 6 Apple Tree(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 176    Accepted Submission(s): 120 Problem Description I've bought an orchard an