PAT--1113. Integer Set Partition
2016-03-16 17:31
309 查看
PAT A.1113
题解
排下序就ok。#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int maxn = 100000 + 10; int n, a[maxn]; int main() { while(cin >> n) { for(int i = 0; i < n; ++i) scanf("%d", a + i); sort(a, a + n); int s1 = 0, s2 = 0; if(n & 1){ for(int i = 0; i <= n / 2 - 1; ++i){ s1 += a[i]; s2 += a[n - i - 1]; } s2 += a[n / 2]; cout << 1 << " " << s2 - s1 << endl; } else{ for(int i = 0; i < n / 2; ++i){ s1 += a[i]; s2 += a[n - i - 1]; } cout << 0 << " " << s2 - s1 << endl; } } }
相关文章推荐
- 在命令行用 sort 进行排序
- Linux Shell - 如何使用sort与uniq命令删除重复的文本行
- Redis sort 排序命令详解
- 批处理命令教学之字符串排序(sort)
- RM格式压缩电影软件 Easy RealMedia Producer Full V1.94 下载
- C++ 关于STL中sort()对struct排序的方法
- C#中Arraylist的sort函数用法实例分析
- Js中sort()方法的用法
- 在IE 浏览器中使用 jquery的fadeIn() 效果 英文字符字体加粗
- js采用concat和sort将N个数组拼接起来的方法
- 如何写JS数组sort的比较函数
- javascript中sort()的用法实例分析
- 比较简单的jquery教程 Easy Ajax with jQuery 中文版全集第1/3页
- Easy RM RMVB to DVD Burner v1.3.8 汉化版 下载 附注册码
- js模拟实现Array的sort方法
- Java数据结构及算法实例:冒泡排序 Bubble Sort
- js表数据排序 sort table data
- javascript 数组排序函数sort和reverse使用介绍
- JavaScript Table排序 2.0 (更新)
- js中数组(Array)的排序(sort)注意事项说明