1113. Integer Set Partition 解析
来源:互联网 发布:网页生成软件 编辑:程序博客网 时间:2024/06/05 02:25
排序然后两头开始加,双数一边一半就好,单数看给左边还是右边。
#include <iostream>#include <vector>#include <algorithm>using namespace std;int n;vector <int> list;int main() {cin >> n;int temp;for (int i = 0; i < n; i++) {scanf("%d",&temp);list.push_back(temp);}sort(list.begin(), list.end());#ifdef _DEBUGfor (int i = 0; i < list.size(); i++) {cout << list[i] << endl;}#endif//处理分组int s1 = 0, s2 = 0;int n1 = 0, n2 = 0;int p1 = 0, p2 = list.size() - 1;while (p1 < p2) {s1 += list[p1];s2 += list[p2];n1++, n2++, p1++, p2--;}if (p1 == p2) {//奇数情况int ts1 = s1 + list[p1], ts2 = s2 + list[p2];if (abs(ts1 - s2) > abs(ts2 - s1)) {s1 = ts1, n1++;}else {s2 = ts2, n2++;}}cout << abs(n1 - n2) << " " << abs(s1 - s2) << endl;return 0;}
0 0
- 1113. Integer Set Partition 解析
- 1113. Integer Set Partition
- 1113. Integer Set Partition
- PAT--1113. Integer Set Partition
- 1113. Integer Set Partition (25)
- 1113. Integer Set Partition (25)
- pat 1113. Integer Set Partition
- 1113. Integer Set Partition (25)
- PAT|1113. Integer Set Partition
- 1113. Integer Set Partition (25)
- 1113. Integer Set Partition (25)
- 【PAT】1113. Integer Set Partition
- 1113. Integer Set Partition (25)
- 1113. Integer Set Partition (25)
- 1113. Integer Set Partition (25)
- 1113. Integer Set Partition (25)
- 1113. Integer Set Partition (25)
- 1113. Integer Set Partition (25)
- 《STL源码剖析》笔记(一)组件之间的关系
- Scala介绍
- thinkphp模型初步
- Java笔记之自动装/拆箱以及类型转换
- Spring Boot(三):Eclipse中引入Spring IDE环境--Spring tool suite
- 1113. Integer Set Partition 解析
- 学习JVM(Java内存管理和OOM)
- oracle函数2
- Android AsyncTask
- Week Training: 516 Longest Palindromic Subsequence
- Java笔记之常用容器浅析
- nginx 启动失败 缺少libpcre.so.1
- 1114. Family Property 解析
- LeetCode刷题(C++)——Balanced Binary Tree(Easy)