这道题第一眼看到以为是一道思维题,
草稿本上写了1小时,其实可以暴力但其实吧可以很容易想到,开始Rahul 不知道Tina的位置,所以为了在任意情况下都最近,他会选择更加靠近中间的位置,而刷油漆的位置也会优先选择靠中间的位置;
所以当Tina开始选位置时,Rahul已经坐在了能坐的位置中最靠近中间的地方,而Tina自然就会选择最远离Rahul的角落。
因为两人都是最优解,且油漆也会优先涂在靠中间的位置确保距离可以加大。所以随着k的增大,两人的距离会越来越远。
#include<iostream>
#include<string.h>
#include<queue>
#include<algorithm>
#define int long long
using namespace std;
priority_queue<int,vector<int>,greater<int> >mp;//利用优先队列自动排序
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t; cin >> t;
while (t--)
{
int n, m; cin >> n >> m;
for (int i = 1; i <= n; i++)
{
int x = max(i-1, n - i);
for (int j = 1; j <= m; j++)
{
int y = max(j-1, m - j);
mp.push(x + y);
//cout << x << " " << y << " " << x + y << endl;
}
}
while (!mp.empty())
{
cout << mp.top() << " ";
mp.pop();
}
cout << endl;
}
}