【PAT甲级】1113 Integer Set Partition (25分)
题意:
输入一个正整数N(2<=N<=1e5),接着输入N个正整数,将这些数字划分为两个不相交的集合,使得他们的元素个数差绝对值最小且元素和差绝对值最大。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for(int i=;i<=n;++i)
cin>>a[i];
sort(a+,a++n);
long long sum=,sum2=;
for(int i=;i<=n/;++i)
sum+=a[i];
for(int i=n/+;i<=n;++i)
sum2+=a[i];
cout<<n%<<" "<<sum2-sum;
return ;
}
【PAT甲级】1113 Integer Set Partition (25分)的更多相关文章
- PAT 甲级 1113 Integer Set Partition
https://pintia.cn/problem-sets/994805342720868352/problems/994805357258326016 Given a set of N (> ...
- PAT 甲级 1083 List Grades (25 分)
1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...
- PAT甲级——1130 Infix Expression (25 分)
1130 Infix Expression (25 分)(找规律.中序遍历) 我是先在CSDN上面发表的这篇文章https://blog.csdn.net/weixin_44385565/articl ...
- PAT 甲级 1074 Reversing Linked List (25 分)(链表部分逆置,结合使用双端队列和栈,其实使用vector更简单呐)
1074 Reversing Linked List (25 分) Given a constant K and a singly linked list L, you are supposed ...
- PAT 甲级 1086 Tree Traversals Again (25分)(先序中序链表建树,求后序)***重点复习
1086 Tree Traversals Again (25分) An inorder binary tree traversal can be implemented in a non-recu ...
- PAT 甲级 1052 Linked List Sorting (25 分)(数组模拟链表,没注意到不一定所有节点都在链表里)
1052 Linked List Sorting (25 分) A linked list consists of a series of structures, which are not ne ...
- PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)
1040 Longest Symmetric String (25 分) Given a string, you are supposed to output the length of the ...
- PAT 甲级 1036 Boys vs Girls (25 分)(简单题)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade ...
- PAT 甲级 1062 Talent and Virtue (25 分)(简单,结构体排序)
1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a histor ...
随机推荐
- scrapy框架综合运用 爬取天气预报 + 定时任务
爬取目标网站: http://www.weather.com.cn/ 具体区域天气地址: http://www.weather.com.cn/weather1d/101280601.shtm(深圳) ...
- Deep Clustering Algorithms
Deep Clustering Algorithms 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 本文研究路线:深度自编码器(Deep Autoen ...
- Linux安装U盘启动报错Failed to load ldlinux.c32
报错信息 使用U盘安装linux无法正常启动 Start booting from USB device... SYSLINUX 5.10 EDD 2013-06-04 Copyright (C) 1 ...
- react-native构建基本页面3---路由配置
安装路由 运行yarn add react-native-router-flux 路由官网 路由相关配置 路由简单的DEMO // Main 才是项目的根组件 import React, { Comp ...
- 使用xshell
将选定的文本自动复制到剪贴板 并且 鼠标向右按钮定义为粘贴剪贴板内容
- 扩展BSGS求解离散对数问题
扩展BSGS用于求解axΞb mod(n) 同余方程中gcd(a,n)≠1的情况 基本思路,将原方程转化为a与n互质的情况后再套用普通的BSGS求解即可 const int maxint=((1< ...
- Yeoman+Bower+gulp web前端自动化工作流程(初级教程)
Yeoman包括了三个部分yo(脚手架工具).grunt/gulp(构建工具).bower(包管理器).听说gulp更容易上手,所以我就没用grunt而选的gulp 什么是开发流程? 在我看来一个完整 ...
- K3/Cloud 用插件打开一张已存在的单据
BillShowParameter billpara = new BillShowParameter();billpara.FormId = "SAL_SaleOrder";//单 ...
- RN开发-IDE和API
一.开发工具 1.Visual Studio Code:微软IDE,轻量级,只有30+M大小 2.nuclide :仅支持Mac 3.WebStorm : JavaScript开发工具(IDE) 二. ...
- I+Me=完整的自我
这是这个系列的第二篇文章,如同第一篇一样,这篇文章会在24小时后删除. 之所以如此极端,因为我自认为这篇文章很有价值,不以这种方式,大家即使看了,也只会一带而过,不会真的汲取到营养. 这篇文章涉及的关 ...