Codeforces 594A - Warrior and Archer

题目大意:给你在一条线上的n(偶数)个点,mike和alice 开始禁点,他们轮流开始,直到最后只剩下两个点,

mike希望剩下的两个点距离尽可能小,alice希望剩下的两个点距离尽可能大,他们都采用最优策略,问你最后

剩下的两个点是什么。

这种脑洞题好难啊啊,难受。

思路:我们假定剩下了两个点是 x1 和 x2 ,那么最优考虑,mike拿掉的是<x1 和 >x2的点,alice拿掉的是

x1 和 x2 之间的点,所以我们枚举x1 和 x2,因为mike先选,我们取其中的最小值。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2*1e5+5;
ll a[N];
int n;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) scanf("%I64d",&a[i]);
    sort(a+1,a+1+n);
    ll ans=1e18;
    for(int i=1;i<=n;i++)
    {
        if(i+n/2<=n) ans=min(ans,a[i+n/2]-a[i]);
    }
    cout<<ans<<endl;
    return 0;
}

时间: 2024-10-05 05:03:59

Codeforces 594A - Warrior and Archer的相关文章

codeforces 的20道C题

A - Warrior and Archer CodeForces - 595C n  偶数  然后n个数字 A B 轮流取一个 A让差变小B让差变大 直到最后2 个   求的是最小剩下的差 最后剩下的 L R  相距 n/2    求一下最小的就行 #include <iostream> #include <cstdio> #include <cmath> #include <map> #include <algorithm> #include

2017-5-14-Train:Codeforces Round #330 (Div. 2)

A. Vitaly and Night(模拟) One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment. Vitaly sees a

Unity技巧集合

这篇文章将收集unity的相关技巧,会不断地更新内容. 1)保存运行中的状态 unity在运行状态时是不能够保存的.但在运行时编辑的时候,有时会发现比较好的效果想保存.这时可以在 "Hierarchy"中复制相关对象树,暂停游戏后替换原来的,就可以了. 2)Layer的用法 LayerMask.NameToLayer("Ground");  // 通过名字获取layer[狗刨学习网] 3D Raycast [csharp] view plaincopy Raycas

CodeForces 312B Archer

Archer Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 312B64-bit integer IO format: %I64d      Java class name: (Any) SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to

CodeForces 78D Archer&#39;s Shot

二分. 统计过程如下图: 先统计红线上的个数,然后统计绿线上的个数,然后统计咖啡色线上的个数......一个一个往下跳就可以了. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #inclu

【CodeForces 312B】BUPT 2015 newbie practice #3A Archer

题 SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is  for SmallR while  for Zanoes. The one who shoots in the tar

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th