PAT 甲级 1113 Integer Set Partition
https://pintia.cn/problem-sets/994805342720868352/problems/994805357258326016
Given a set of N (>) positive integers, you are supposed to partition them into two disjoint sets A1 and A2 of n1 and n2 numbers, respectively. Let S1 and S2denote the sums of all the numbers in A1 and A2, respectively. You are supposed to make the partition so that ∣ is minimized first, and then ∣ is maximized.
Input Specification:
Each input file contains one test case. For each case, the first line gives an integer N (2), and then N positive integers follow in the next line, separated by spaces. It is guaranteed that all the integers and their sum are less than 231.
Output Specification:
For each case, print in a line two numbers: ∣ and ∣, separated by exactly one space.
Sample Input 1:
10
23 8 10 99 46 2333 46 1 666 555
Sample Output 1:
0 3611
Sample Input 2:
13
110 79 218 69 3721 100 29 135 2 6 13 5188 85
Sample Output 2:
1 9359
代码:
#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10;
int N;
int num[maxn]; int main() {
scanf("%d", &N);
int sum = 0;
for(int i = 0; i < N; i ++) {
scanf("%d", &num[i]);
sum += num[i];
} sort(num, num + N);
int ans = 0;
for(int i = 0; i < N / 2; i ++)
ans += num[i]; printf("%d %d\n", N % 2, sum - 2 * ans);
return 0;
}
好久不写手生生 今天是 Be 主决心减肥的第一天
PAT 甲级 1113 Integer Set Partition的更多相关文章
- PAT甲级——A1113 Integer Set Partition
Given a set of N (>) positive integers, you are supposed to partition them into two disjoint sets ...
- 1113 Integer Set Partition (25 分)
1113 Integer Set Partition (25 分) Given a set of N (>1) positive integers, you are supposed to pa ...
- PAT甲级1103. Integer Factorization
PAT甲级1103. Integer Factorization 题意: 正整数N的K-P分解是将N写入K个正整数的P次幂的和.你应该写一个程序来找到任何正整数N,K和P的N的K-P分解. 输入规格: ...
- 【PAT甲级】1113 Integer Set Partition (25分)
题意: 输入一个正整数N(2<=N<=1e5),接着输入N个正整数,将这些数字划分为两个不相交的集合,使得他们的元素个数差绝对值最小且元素和差绝对值最大. AAAAAccepted cod ...
- PAT 1113 Integer Set Partition
Given a set of N (>1) positive integers, you are supposed to partition them into two disjoint set ...
- PAT (Advanced Level) 1113. Integer Set Partition (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- 1113. Integer Set Partition (25)
Given a set of N (> 1) positive integers, you are supposed to partition them into two disjoint se ...
- 1113 Integer Set Partition
Given a set of N (>) positive integers, you are supposed to partition them into two disjoint sets ...
- PAT甲级——1103 Integer Factorization (DFS)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90574720 1103 Integer Factorizatio ...
随机推荐
- HDU3045 Picnic Cows
题面 HDU vjudge 题解 将权值排序,则分组一定是连续的 设$f[i]$表示前$i$头牛的最小代价,则($a[i]$为$i$的权值): $$ f[i] = f[j - 1] + sum[i] ...
- [算法]用JAVA实现快速排序
问题描述: 实现对数组的普通快速排序与随机快速排序实验要求: (1)实现上述两个算法 (2)统计算法的运行时间 (3)分析性能差异,作出总结 代码: 一:普通快速排序 public class Qui ...
- Codeforces 912 E.Prime Gift (折半枚举、二分)
题目链接:Prime Gift 题意: 给出了n(1<=n<=16)个互不相同的质数pi(2<=pi<=100),现在要求第k大个约数全在所给质数集的数.(保证这个数不超过1e ...
- restful_framework之视图组件
一.基本视图 写一个出版社的增删查改resful接口 要自己事先创建好django项目,并创建好表,添加完记录 路由: url(r'^publish/$', views.PublishView.as_ ...
- 总结几种常见web攻击手段及其防御方式
本文简单介绍几种常见的攻击手段及其防御方式 XSS(跨站脚本攻击) CSRF(跨站请求伪造) SQL注入 DDOS web安全系列目录 总结几种常见web攻击手段极其防御方式 总结几种常见的安全算法 ...
- int str input的运用
- hashCode及HashMap中的hash()函数
一.hashcode是什么 要理解hashcode首先要理解hash表这个概念 1. 哈希表 hash表也称散列表(Hash table),是根据关键码值(Key value)而直接进行访问的数据结构 ...
- Siki_Unity_7-4_高自由度沙盘游戏地图生成_MineCraft_Uniblocks插件(可拓展)
Unity 7-4 高自由度沙盘游戏地图生成 MineCraft (插件Uniblocks) 任务1&2&3&4 素材 && 课程演示 && 课 ...
- Webrtc源码走读(一)
阅读event_wrapper.h event_wrapper_win.cpp 的实现 自己对“事件”这个词没有深的理解,通过看段代码,好像有点感觉,类似与C#的AutoResetEvent
- Hyperledger Fabric CA User’s Guide——配置设置(四)
配置设置 Fabric CA提供了三种方案去配置Fabric CA服务端和客户端,优先顺序是: CLI flags(标识) 环境变量 配置文件 在本文档的其余部分中,我们将对配置文件进行更改.但是,可 ...