codeforces594A/616B+博弈(最大值最小)

output
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.
Input

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.
Output

Print the distance between the warrior and the archer at the beginning of the fight, provided that both Vova and Lesha play optimally.
Examples
Input

6
0 1 3 7 15 31

Output

7

Input

2
73 37

Output

36

Note

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个点(n为偶数),Vova和Lesha轮流,每次删一个点,让最后只剩下两个点。Vova想让剩下的两个点距离最小,Lesha想要最大。Vova先手。问最优策略下剩下两点的距离。
解法:按照对称性原则,找到i,与n/2+i的距离中最小的那个,每次按照对称性博弈。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<cassert>
#define LL long long
#define debug(x) cout<<x<<endl;

using namespace std;

int a[200005];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    int ans=1e9;
    for(int i=0;i<n/2;i++) ans=min(ans,a[i+n/2]-a[i]);
    printf("%d\n",ans);
    return 0;
}

Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn’t want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.

Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.

Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.
Input

The first line contains two integers n, m (1 ≤ n, m ≤ 100) — the number of streets and avenues in Munhattan.

Each of the next n lines contains m integers cij (1 ≤ cij ≤ 109) — the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.
Output

Print the only integer a — the cost of the dinner for Jack and Emma.
Examples
Input

3 4
4 1 3 5
2 2 2 2
5 4 5 1

Output

2

Input

3 3
1 2 3
2 3 1
3 1 2

Output

1

Note

In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.

In the second example regardless of Emma’s choice Jack can choose a restaurant with the cost of the dinner 1.

题意:有n条横着的街和m条竖着的街,每个交叉口有家餐馆,并给出价格,Emma选横着的街,Jack 选竖着的街,Emma想让价格越贵越好。Jack想让价格越小越好,Emma先选,问最后大家都能接受的价格。
解法:无论Emma选哪条街,Jack会选这条中最小的那个,所以,Emma最好选每条街中最小值最大的那个。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<map>
#include<vector>
#define LL long long
#define inf 0x3f3f3f3f
using namespace std;


int n,m,cost;
int main(){
    int ans=0;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++){
        int temp=inf;
        for(int j=1;j<=m;j++){
            scanf("%d",&cost);
            temp=min(temp,cost);
        }
        ans=max(ans,temp);
    }
    printf("%d\n",ans);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值