Codeforces Round #594 (Div. 2) B. Grow The Tree
发布日期:2022-02-17 09:51:12 浏览次数:7 分类:技术文章

本文共 731 字,大约阅读时间需要 2 分钟。

Codeforces Round #594 (Div. 2) B. Grow The Tree

题意

给你几个棍子,问如何摆(垂直)使得两端距离最远

思路

可以当成一个直角三角形来理解

把给的棍子从小到大排序 把前半部分加起来作为直角三角形一条边 后半部分加起来当做一条边

#include 
#include
#include
using namespace std;typedef long long ll;int a[(int)1e6+7];int main(void){
int n; scanf("%d", &n); for (int i = 0; i < n; i++) {
scanf("%d", &a[i]); } sort(a, a + n); ll s1 = 0, s2 = 0; for (int i = 0; i < n; ++i) {
if (i < n / 2) {
s1 += a[i]; } else {
s2 += a[i]; } } printf("%lld\n", s1 * s1 + s2 * s2); return 0;}

转载地址:https://blog.csdn.net/qq_43826794/article/details/102652478 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:UVA 10048 Audiophobia (Floyd变形)
下一篇:POJ - 1679 The Uinque MST

发表评论

最新留言

关注你微信了!
[***.104.42.241]2024年04月01日 12时24分45秒