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$,就代表这个字符 ...
 
随机推荐
- django下进行项目的部署
			
-------------------Django下进行对应的服务器配置1.服务器购买 本人在阿里云购买了一个服务器,操作系统为windows server2008/Linux(ubuntu) 2.服 ...
 - 使用CefSharp 在C#用户控件中嵌入Chrome浏览器使用方法
			
CEF(Chromium Embedded Framework, 嵌入式Chromium框架)是C/C++开发的库 目前 Google Chrome(Google浏览器),Chromium浏览器,Op ...
 - 常用bash命令
			
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px "Helvetica Neue"; color: #454545 } p. ...
 - plsql developer 恢复默认布局界面
			
tools-preferences-appearance-(reset docking,reset toolbars)
 - 【grunt】两小时入门
			
目录: 1. 用途和场景 2.Grunt插件 3.相关资源 4.环境安装 5.开始学习 5.1 一个新项目 5.2 生成package.json 5.3 在项目中安装grunt和相关插件 5.4 Gr ...
 - jmeter3.2 创建webservice 测试
			
1.创建测试计划 templates→select Template→Building a SOAP WebService Test Plan 2.修改HTTP Request Defaults中的参 ...
 - python 求解线性方程组
			
Python线性方程组求解 求解线性方程组比较简单,只需要用到一个函数(scipy.linalg.solve)就可以了.比如我们要求以下方程的解,这是一个非齐次线性方程组: 3x_1 + x_2 - ...
 - Winform控件输入的字母转换成大写
			
private void textBoxHbh_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar >= 'a' & ...
 - Nginx做文件下载服务器
			
这是最简单的一种办法,贴完代码就能用 server { listen 80; charset utf-8; server_name localhost; root /data/file/; autoi ...
 - 201521123082 《Java程序设计》第13周学习总结
			
201521123082 <Java程序设计>第13周学习总结 标签(空格分隔): java 1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. ...