Codeforces Round #330 (Div. 2) C. Warrior and Archer(贪心博弈)
来源:互联网 发布:数据库表如何设计null 编辑:程序博客网 时间:2024/05/29 09:59
题意:
给定N≤2×105偶数个坐标,2个绝顶聪明的人玩游戏,轮流ban掉N−2个坐标
甲要使得最终2个尽可能近,乙则反之
求最终两个坐标的距离
分析:
假设[al,ar]是最终留下的坐标,可以发现甲一定选区间内的点,乙则反之
由于博弈,r−l≤n2,那么ans=minn2i=1{ai+n2−ai}
代码:
//// Created by TaoSama on 2016-01-21// Copyright (c) 2015 TaoSama. All rights reserved.//#pragma comment(linker, "/STACK:1024000000,1024000000")#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;#define pr(x) cout << #x << " = " << x << " "#define prln(x) cout << #x << " = " << x << endlconst 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;}
0 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 595C Warrior and Archer(博弈)
- Codeforces Round #330 (Div. 1) A. Warrior and Archer
- [CodeForces 595C] Warrior and Archer (无胜负最优值博弈)
- codeforces 594A Warrior and Archer [对称博弈]【博弈】
- Codeforces Round #228 (Div. 2) E Fox and Card Game(贪心博弈)
- Codeforces 594A - Warrior and Archer (思维)
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts 贪心
- Codeforces Round #346 (Div. 2) C. Tanya and Toys 贪心
- Codeforces Round #419 (Div. 2) C. Karen and Game【贪心】
- Codeforces Round #406 (Div. 2) C 博弈
- Codeforces Round #263 (Div. 2) C. Appleman and Toastman(贪心)
- Codeforces Round #277.5 (Div. 2)---C. Given Length and Sum of Digits (贪心)
- 2013年第四届蓝桥杯C/C++程序设计本科B组省赛 马虎的算式(结果填空)
- HDOJ 2044 一只小蜜蜂...
- 双硬盘安装win7 64位&ubuntu 64位双系统注意事项
- List<T>的各种排序方法
- 关于UIViewController self.title在IOS7中默认是黑色且字体稍小的解决办法
- Codeforces Round #330 (Div. 2) C. Warrior and Archer(贪心博弈)
- GameScene 三木运算符
- 2013年第四届蓝桥杯C/C++程序设计本科B组省赛 第39级台阶(结果填空)
- 命令行向Php传递参数的两种方式
- 新浪微博Android-SDK分享网页功能
- 技术学习过程
- hdu acm 1116 Play on Words
- Intellij idea创建javaWeb以及Servlet简单实现
- Codeforces 617EXOR and Favorite Number