PAT甲级——A1113 Integer Set Partition
Given a set of N (>) positive integers, you are supposed to partition them into two disjoint sets A1 and A2 of n1and n2 numbers, respectively. Let S1 and S2 denote 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 Npositive 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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, s1 = , s2 = , nMin, sMin;
int main()
{
cin >> n;
vector<int>v(n);
for (int i = ; i < n; ++i)
cin >> v[i];
sort(v.begin(), v.end());
for (int i = ; i < n; ++i)
{
if (i < n / )
s1 += v[i];
else
s2 += v[i];
}
cout << n % << " " << s2 - s1 << endl;
return ;
}
PAT甲级——A1113 Integer Set Partition的更多相关文章
- PAT 甲级 1113 Integer Set Partition
https://pintia.cn/problem-sets/994805342720868352/problems/994805357258326016 Given a set of N (> ...
- PAT甲级1103. Integer Factorization
PAT甲级1103. Integer Factorization 题意: 正整数N的K-P分解是将N写入K个正整数的P次幂的和.你应该写一个程序来找到任何正整数N,K和P的N的K-P分解. 输入规格: ...
- PAT A1113 Integer Set Partition (25 分)——排序题
Given a set of N (>1) positive integers, you are supposed to partition them into two disjoint set ...
- A1113. Integer Set Partition
Given a set of N (> 1) positive integers, you are supposed to partition them into two disjoint se ...
- PAT甲级——1103 Integer Factorization (DFS)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90574720 1103 Integer Factorizatio ...
- A1113 | Integer Set Partition (25)
太简单了 #include <stdio.h> #include <memory.h> #include <math.h> #include <string& ...
- PAT甲级——A1103 Integer Factorization
The K−P factorization of a positive integer N is to write N as the sum of the P-th power of Kpositiv ...
- PAT甲级1103 Integer Factorization【dfs】【剪枝】
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805364711604224 题意: 给定一个数n,要求从1~n中找 ...
- PAT_A1113#Integer Set Partition
Source: PAT A1113 Integer Set Partition (25 分) Description: Given a set of N (>) positive integer ...
随机推荐
- H5新增的postMessage跨域解决方案Demo
Demo背景:html中使用iframe嵌入了跨域的vue项目,在html中将参数传入到跨越的vue项目中. 向跨越的子窗口中发送数据 function sendMessage(data) { // ...
- swiper缩略图active切换失灵的解决思路
报错信息:Cannot read property ‘indexOf’ of undefined swiper. 来源是swiper.min.js,首先检查自己写的js配置是否有误,没有就调试插件源代 ...
- 40 VSCode下.json文件的编写——(1) linux/g++ (2).json中参数与预定义变量的意义解释
0 引言 转入linux/VSCode编程之后,迫切了解到有必有较为系统地学习一下VSCode中相关配置文件的写法.下面将分为 linux/g++编译指令..json文件关键词/替换变量的意义.编译链 ...
- kafka和flume进行整合的日志采集的confi文件编写
配置flume.conf 为我们的source channel sink起名 a1.sources = r1 a1.channels = c1 a1.sinks = k1 指定我们的source收集到 ...
- [C#]记录一次异常排查,关于using语法、sqlserver数据库session、DBHelper类
最近在做一个基于asp.net和sqlserver的网站项目,发现网站运行一段时间之后,会报异常: 超时时间已到,但是尚未从池中获取连接.出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小 ...
- 3. Image Structure and Generation
名词 Extensible Linking Format(ELF) 3.1 The structure of an ARM ELF image ARM ELF映像包含sections, regions ...
- MySQL数据库中,使用 group by 时,不重复字段如何拼接显示
就不写文字描述了,直接用图和sql来表述吧. 这是测试数据,表名为 person 现在,我想按照性别进行分组,也就是字段 sex ,同时能将分组后的姓名全部显示出来. sql 语句如下: SELECT ...
- 全面解析HTML5优缺点
HTML5是当下最主流的网页标准,它的出现给在线应用和手机游戏开发者带来了不少新机会.基于HTML5,开发者可以制作自己的网络游戏,而这个游戏无 论你在PC.手机还是平板电脑上,无论你用Chrome. ...
- 关于JQuery Ajax 跨域 访问.net WebService
关于这个 jQuery Ajax跨域访问 WebService 前天整了好几个小时没整明白 今天再看一下 结果突然就顿悟了 1.建一个空webApplication --添加--新建项--web服务( ...
- matplotlib画图出现乱码情况
python3使用matplotlib画图,因python3默认使用中unicode编码,所以在写代码时不再需要写 plt.xlabel(u’人数’),而是直接写plt.xlabel(‘人数’). 注 ...