http://codeforces.com/problemset/problem/594/A
2 seconds
256 megabytes
standard input
standard output
In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model solution corresponds to what jury wanted it to be during the contest.
Vova and Lesha are friends. They often meet at Vova's place and compete against each other in a computer game named The Ancient Papyri: Swordsink. Vova always chooses a warrior as his fighter and Leshac chooses an archer. After that they should choose initial positions for their characters and start the fight. A warrior is good at melee combat, so Vova will try to make the distance between fighters as small as possible. An archer prefers to keep the enemy at a distance, so Lesha will try to make the initial distance as large as possible.
There are n (n is always even) possible starting positions for characters marked along the Ox axis. The positions are given by their distinct coordinates x1, x2, ..., xn, two characters cannot end up at the same position.
Vova and Lesha take turns banning available positions, Vova moves first. During each turn one of the guys bans exactly one of the remaining positions. Banned positions cannot be used by both Vova and Lesha. They continue to make moves until there are only two possible positions remaining (thus, the total number of moves will be n - 2). After that Vova's character takes the position with the lesser coordinate and Lesha's character takes the position with the bigger coordinate and the guys start fighting.
Vova and Lesha are already tired by the game of choosing positions, as they need to play it before every fight, so they asked you (the developer of the The Ancient Papyri: Swordsink) to write a module that would automatically determine the distance at which the warrior and the archer will start fighting if both Vova and Lesha play optimally.
The first line on the input contains a single integer n (2 ≤ n ≤ 200 000, n is even) — the number of positions available initially. The second line contains n distinct integers x1, x2, ..., xn (0 ≤ xi ≤ 109), giving the coordinates of the corresponding positions.
Print the distance between the warrior and the archer at the beginning of the fight, provided that both Vova and Lesha play optimally.
6
0 1 3 7 15 31
7
2
73 37
36
In the first sample one of the optimum behavior of the players looks like that:
- Vova bans the position at coordinate 15;
- Lesha bans the position at coordinate 3;
- Vova bans the position at coordinate 31;
- Lesha bans the position at coordinate 1.
After these actions only positions 0 and 7 will remain, and the distance between them is equal to 7.
In the second sample there are only two possible positions, so there will be no bans.
题意:两个人玩游戏,开始有n(偶数)个位置,两人轮流禁用位置,先禁用的人想让最后两个位置距离最小,后禁用的想最大。给你数组a[]表示位置。求禁用完后的距离。
题解:第一个人会禁用最小或者最大的位置,来减少最大距离,第二给人会禁用最中间的数来增加最小距离,所以答案是a[i+n/2]-a[i]其中一个的,由于想要距离最少的人先bans,所以答案为a[i+n/2]-a[i]中的最小值
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<fstream>
#include<algorithm>
#include<cstring>
#include<iomanip>
using namespace std;
const int maxn=2e5+;
int a[maxn],n;
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
sort(a+,a++n);
int ans=1e9+;
for(int i=;i+n/<=n;i++)ans=min(ans,a[i+n/]-a[i]);
printf("%d\n",ans);
}
http://codeforces.com/problemset/problem/594/A的更多相关文章
- http://codeforces.com/problemset/problem/712/D
D. Memory and Scores time limit per test 2 seconds memory limit per test 512 megabytes input standar ...
- codeforces.com/problemset/problem/213/C
虽然一开始就觉得从右下角左上角直接dp2次是不行的,后面还是这么写了WA了 两次最大的并不一定是最大的,这个虽然一眼就能看出,第一次可能会影响第二次让第二次太小. 这是原因. 5 4 32 1 18 ...
- http://codeforces.com/problemset/problem/847/E
E. Packmen time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- http://codeforces.com/problemset/problem/545/D
D. Queue time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- codeforces 340C Tourist Problem
link:http://codeforces.com/problemset/problem/340/C 开始一点也没思路,赛后看别人写的代码那么短,可是不知道怎么推出来的啊! 后来明白了. 首先考虑第 ...
- codeforces B. Routine Problem 解题报告
题目链接:http://codeforces.com/problemset/problem/337/B 看到这个题目,觉得特别有意思,因为有熟悉的图片(看过的一部电影).接着让我很意外的是,在纸上比划 ...
- Codeforces 527D Clique Problem
http://codeforces.com/problemset/problem/527/D 题意:给出一些点的xi和wi,当|xi−xj|≥wi+wj的时候,两点间存在一条边,找出一个最大的集合,集 ...
- Codeforces 706C - Hard problem - [DP]
题目链接:https://codeforces.com/problemset/problem/706/C 题意: 给出 $n$ 个字符串,对于第 $i$ 个字符串,你可以选择花费 $c_i$ 来将它整 ...
- Codeforces 1096D - Easy Problem - [DP]
题目链接:http://codeforces.com/problemset/problem/1096/D 题意: 给出一个小写字母组成的字符串,如果该字符串的某个子序列为 $hard$,就代表这个字符 ...
随机推荐
- python3 requests 获取 拉勾工作数据
#-*- coding:utf-8 -*- __author__ = "carry" import requests,json for x in range(1, 15): url ...
- pip源相关问题
指定源地址安装: pip install -i http://pypi.douban.com/simple/ packagename pip install -i http://pypi.tuna.t ...
- 微信网页授权封装接口——node.js版
Wechat 网页授权 授权url:(请在微信客户端中打开此链接体验) xxx为config.js中的WECHAT_DOMAIN 1.scope为snsapi_base xxx/?route=auth ...
- JDK和Tomcat部署
author:JevonWei 版权声明:原创作品 JDK就是Java Development Kit.简单的说JDK是面向开发人员使用的SDK,它提供了Java的开发环境和运行环境.SDK是Soft ...
- spring配置和注解事务同时存在导致的事务嵌套
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt123 首先先看配置文件: [html] view plaincopy < ...
- 第4阶段——制作根文件系统之分析init进程(2)
本节目标: (1) 了解busybox(init进程和命令都放在busybox中) (2) 创建SI工程,分析busybox源码来知道init进程做了哪些事情 (3) 分析busybox中init进 ...
- VHDL学习记录
VHDL全名Very-High-Speed Integrated Circuit Hardware Description Language ,是一种标准硬件描述语言.下面通过60进制计数器来分析VH ...
- 原生的AJAX
var XHR=null; if (window.XMLHttpRequest) { // 非IE内核 XHR = new XMLHttpRequest(); } else if (window.Ac ...
- 【集美大学1411_助教博客】团队作业8——第二次项目冲刺(Beta阶段)
写在前面的话 此次团队作业8可以拆分成两部分:1.beta阶段冲刺计划安排,2.7天敏捷冲刺."我们很低调"没有使用leangoo,经过与张老师的商议,张老师同意他们不使用lean ...
- 201521123083《Java程序设计》第13周学习总结
本次作业参考文件 正则表达式参考资料 1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. 2. 书面作业 1. 网络基础 1.1 比较ping www.bai ...