Codeforces Round #330 (Div. 2)C. Warrior and Archer(博弈)
来源:互联网 发布:centos apt 编辑:程序博客网 时间:2024/06/10 13:27
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.
60 1 3 7 15 31
7
273 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.
题意:x轴坐标上有n个点,两个人轮流做游戏,每轮到一个人他可以抹去x上的一个点。总共进行n-2轮。
因此x轴上一定会剩下两个点,先手希望最后剩的两个点的距离尽可能小,后手反之。问你最后剩下两点的距离。
题解:先手为了让距离变小,他会尽可能的选择左右两端的点,而后手一定会选择中间的某些点。
因此我们可以想到,最后剩下的两点之间的距离一定是n/2-1,又因为先手让距离尽可能小,所以我们枚举两点
找最小距离即可。。。
#include<set> #include<map> #include<stack> #include<queue> #include<vector> #include<string> #include<time.h> #include<math.h> #include<stdio.h> #include<iostream> #include<string.h> #include<stdlib.h> #include<algorithm> #include<functional> using namespace std; #define ll long long #define inf 1000000000 #define mod 1000000007 #define maxn 205000 #define lowbit(x) (x&-x) #define eps 1e-9 #define INF 225int a[maxn];int main(void){int n,i,ans=1000000002;scanf("%d",&n);for(i=1;i<=n;i++)scanf("%d",&a[i]);sort(a+1,a+n+1);for(i=1;i<=n/2;i++)ans=min(ans,a[n/2+i]-a[i]);printf("%d\n",ans);return 0;}
- Codeforces Round #330 (Div. 2)C. Warrior and Archer(博弈,贪心)
- Codeforces Round #330 (Div. 2) C. Warrior and Archer(贪心博弈)
- Codeforces Round #330 (Div. 2)C. Warrior and Archer(博弈)
- Codeforces Round #330 (Div. 2)C. Warrior and Archer【博弈+逆向思维】
- Codeforces Round #330 (Div. 2)C. Warrior and Archer
- codeforces 595C Warrior and Archer(博弈)
- Codeforces Round #330 (Div. 1) A. Warrior and Archer
- CodeForces 595C Warrior and Archer(贪心博弈)
- [CodeForces 595C] Warrior and Archer (无胜负最优值博弈)
- codeforces 594A Warrior and Archer [对称博弈]【博弈】
- Codeforces 594A - Warrior and Archer (思维)
- Codeforces Round #406 (Div. 2) C 博弈
- Codeforces Round #432 (Div. 2) (Codeforces 850C) E. Arpa and a game with Mojtaba 博弈+状态压缩
- C. Anya and Ghosts(Codeforces Round #288 (Div. 2))
- C. Vanya and Scales(Codeforces Round #308 (Div. 2))
- Codeforces Round #371 (Div. 2)C. Sonya and Queries
- Codeforces Round #228 (Div. 2) E Fox and Card Game(贪心博弈)
- Codeforces Round #417 (Div. 2) E. Sagheer and Apple Tree (树上尼姆博弈)
- qbxt国庆水题记day1
- linux中切换为root用户
- 网页随机格言生成器
- opencv-python(7):颜色空间转换
- oracle 11g64 位 安装文件
- Codeforces Round #330 (Div. 2)C. Warrior and Archer(博弈)
- 数据结构实验之链表二:逆序建立链表
- 清北学堂-D7-T1-bst
- Computer Architecture Background
- centos上安装samtool具体步骤
- Html5_animation动画
- get请求
- leetcode 105 /106 . Construct Binary Tree
- Session实现原理深入讨论