Codeforces Round #766 (Div. 2) B. Not Sitting【暴力+堆优化】

Problem - 1627B - Codeforces

        这道题第一眼看到以为是一道思维题,草稿本上写了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;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值