Codeforces Round #330 (Div. 2) C. Warrior and Archer(贪心博弈)

题意:

N2×105,2,banN2
使2,

分析:

[al,ar],,
,rln2,ans=minn2i=1{ai+n2ai}

代码:

//
//  Created by TaoSama on 2016-01-21
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 2e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int n, a[N];

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    while(scanf("%d", &n) == 1) {
        for(int i = 1; i <= n; ++i) scanf("%d", a + i);
        sort(a + 1, a + 1 + n);
        int ans = INF;
        for(int i = 1; i <= n >> 1; ++i)
            ans = min(ans, a[i + n / 2] - a[i]);
        printf("%d\n", ans);
    }
    return 0;
}

你可能感兴趣的:(贪心,博弈)