A1113 | Integer Set Partition (25)

太简单了

#include <stdio.h>
#include <memory.h>
#include <math.h>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <map>

#define I scanf
#define OL puts
#define O printf
#define F(a,b,c) for(a=b;a<c;a++)
#define FF(a,b) for(a=0;a<b;a++)
#define FG(a,b) for(a=b-1;a>=0;a--)
#define LEN 100000
#define MAX 0x06FFFFFF
#define V vector<int>

using namespace std;

int a[LEN];//1e6

int main(){
    freopen("d:/input/A1113/2.txt","r",stdin);
    int i=0,n;
    scanf("%d",&n);
    while(i<n){
        scanf("%d",&a[i]);
        i++;
    }
    int sl=0,sr=0;
    int mid=n/2;//[0,mid),[mid,n)
    sort(a,a+n);
    FF(i,mid) sl+=a[i];
    F(i,mid,n) sr+=a[i];
    O("%d %d",n%2,abs(sl-sr));
    return 0;
}

原文地址:https://www.cnblogs.com/TQCAI/p/8167871.html

时间: 2024-10-30 04:06:22

A1113 | Integer Set Partition (25)的相关文章

1113 Integer Set Partition (25 分)

1113 Integer Set Partition (25 分) Given a set of N (>) positive integers, you are supposed to partition them into two disjoint sets A?1?? and A?2?? of n?1?? and n?2?? numbers, respectively. Let S?1?? and S?2?? denote the sums of all the numbers in A?

PAT A1113 Integer Set Partition (25 分)——排序题

Given a set of N (>1) positive integers, you are supposed to partition them into two disjoint sets A?1?? and A?2?? of n?1?? and n?2?? numbers, respectively. Let S?1?? and S?2?? denote the sums of all the numbers in A?1?? and A?2??, respectively. You

PAT (Advanced Level) 1113. Integer Set Partition (25)

简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; long long a[100000+10]; long long sum=0,sum2; i

PAT A1113 Integer Set Partition [模拟]

题目描述 链接 给一堆数,分成两堆,要求两堆数目差值最小,其次追求两堆的差值尽量大 分析 排序 代码 #include<bits/stdc++.h> using namespace std; int n; const int maxn = 1e5+10; int a[maxn]; int main(){ cin>>n; int s1 = 0, s2 = 0; for(int i=0;i<n;i++){ cin>>a[i]; } sort(a,a+n); for(i

PAT 1113 Integer Set Partition

Given a set of N (>1) positive integers, you are supposed to partition them into two disjoint sets A1 and A2 of n1?? and n?2 numbers, respectively. Let S1? and S?2 denote the sums of all the numbers in A?1?? and A?2?? , respectively. You are supposed

A题目

1 1001 A+B Format(20) 2 1002 A+B for Polynomials(25) 3 1003 Emergency(25) 4 1004 Counting Leaves(30) 5 1005 Spell It Right(20) 6 1006 Sign In and Sign Out(25) 7 1007 Maximum Subsequence Sum(25) 8 1008 Elevator(20) 9 1009 Product of Polynomials(25) 10

FJNU 1152 Fat Brother And Integer(胖哥与整数)

Time Limit: 1000MS   Memory Limit: 257792K [Description] [题目描述] Fat brother recently studied number theory, him came across a very big problem — minimum does not appear positive integer. Fat brother get n positive integers, he needs to find out the l

Integer与int的种种比较

package com.lxm.basics; public class IntegerTest { public static void main(String[] args) { Integer a1 = 45; int a2 = 45; Integer a3 = Integer.valueOf(45); Integer a4 = new Integer(45); Integer a5 = new Integer(45); System.out.println("a1==a2:"+

Integer 与int类型的区别使用

区别一: Java 为每个原始类型提供了包装类型:  - 原始类型: boolean,char,byte,short,int,long,float,double  - 包装类型:Boolean,Character,Byte,Short,Integer,Long,Float,DoubleInteger与int的区别最基本的是:Ingeter是int的包装类,int的初值为0,Ingeter的初值为null1.自动拆箱比较为true 1 @org.junit.Test 2 public void t