Stay Real

HDOJ-6645

由小根堆的性质可以知道,当前最大的值就在叶节点上面,所以只需要排序后依次取就可以了。

#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int n;
long long heap[100005];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while(t--){
cin>>n;
for(int i=1;i<=n;i++){
cin>>heap[i];
}
sort(heap+1,heap+n+1);
bool flag=true;
long long s=0,e=0;
for(int i=n;i>=1;i--){
if(flag){
s+=heap[i];
}else{
e+=heap[i];
}
flag=!flag;
}
cout<<s<<" "<<e<<endl;
}
return 0;
}

HDOJ-6645(简单题+贪心+树)的更多相关文章

  1. 「CQOI2006」简单题 线段树

    「CQOI2006」简单题 线段树 水.区间修改,单点查询.用线段树维护区间\([L,R]\)内的所有\(1\)的个数,懒标记表示为当前区间是否需要反转(相对于区间当前状态),下方标记时懒标记取反即可 ...

  2. 【BZOJ2683】简单题 [分治][树状数组]

    简单题 Time Limit: 50 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 你有一个N*N的棋盘,每个格子内有一 ...

  3. 洛谷P5057 [CQOI2006]简单题(线段树)

    题意 题目链接 Sol 紫色的线段树板子题??... #include<iostream> #include<cstdio> #include<cmath> usi ...

  4. 洛谷 P5057 [CQOI2006]简单题(树状数组)

    嗯... 题目链接:https://www.luogu.org/problem/P5057 首先发现这道题中只有0和1,所以肯定与二进制有关.然后发现这道题需要支持区间更改和单点查询操作,所以首先想到 ...

  5. HDOJ 2037简单的贪心算法

    代码: #include<iostream> using namespace std; int main() { int n,s,t1[100],t2[100],i,t,j; while( ...

  6. bzoj 4066 & bzoj 2683 简单题 —— K-D树(含重构)

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4066 https://www.lydsy.com/JudgeOnline/problem.p ...

  7. bzoj 4066: 简单题 K-D树

    题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=4066 题解 我们把每次的修改操作都当作二维平面上多了一个权值点 对于每组询问可以看做求一 ...

  8. P5057 【[CQOI2006]简单题】

    洛谷P5057[CQOI2006]简单题 差分 树状数组基本操作不说了,主要想记录一下异或下的差分 a数组为每一位的真实值(假设\(a[0]=0\)),t为差分后的数组 则\(t[i]=a[i]\)^ ...

  9. BZOJ_2683_简单题&&BZOJ_1176_[Balkan2007]Mokia_CDQ分治+树状数组

    BZOJ_2683_简单题&&BZOJ_1176_[Balkan2007]Mokia_CDQ分治+树状数组 Description 维护一个W*W的矩阵,初始值均为S.每次操作可以增加 ...

随机推荐

  1. 【hdu 4859】海岸线(图论--网络流最小割)

    题意:有一个区域,有'.'的陆地,'D'的深海域,'E'的浅海域.其中浅海域可以填充为陆地.这里的陆地区域不联通,并且整个地图都处在海洋之中.问填充一定浅海域之后所有岛屿的最长的海岸线之和. 解法:最 ...

  2. CodeCraft-20 (Div. 2) C. Primitive Primes (数学)

    题意:给你两个一元多项式\(f(x)\)和\(g(x)\),保证它们每一项的系数互质,让\(f(x)\)和\(g(x)\)相乘得到\(h(x)\),问\(h(x)\)是否有某一项系数不被\(p\)整除 ...

  3. 继承自List<T>的类通过NewtonJson的序列化问题

    什么问题? NewtonSoft.Json是我们最常用的Json组件库之一了.这里来讨论下使用NewtonSoft.Json序列化List<T>子类的情景.序列化使用了类JsonSeria ...

  4. Nginx基础 - 配置静态web服务

    1.静态参数配置1)文件读取高效sendfile Syntax: sendfile on | off; Default: sendfile off; Context: http, server, lo ...

  5. MSE,RMSE

    MSE: Mean Squared Error 均方误差是指参数估计值与参数真值之差平方的期望值; MSE可以评价数据的变化程度,MSE的值越小,说明预测模型描述实验数据具有更好的精确度. RMSE  ...

  6. css background transparent All In One

    css background transparent All In One opacity ul { max-height: 100px; /* max-height: 187px; */ overf ...

  7. vue & arrow function error

    vue & arrow function error <template> <div class="home"> <img alt=" ...

  8. css text-align-last & text-align

    css text-align-last & text-align css https://caniuse.com/mdn-css_properties_text-align-last http ...

  9. how to stop MongoDB from the command line

    how to stop MongoDB from the command line stop mongod https://docs.mongodb.com/manual/tutorial/manag ...

  10. Chrome new features preview

    Chrome new features preview CSS Overview https://css-tricks.com/new-in-chrome-css-overview/ capture ...