跳到正文

题解

题解:CF2109B Slice to Survive

114514xxx约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年6月17日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 1 分钟
题目
CF2109B

版本

  1. v1当前

思路

我们可以注意到每次现将最多的行或列进行删除肯定是最优的。因此我们可以分类讨论先删除行还是列,并据此计算答案。

因为 Fouad 可以到未被删除的的任意区域,所以到中间肯定是最划算的,所以我们抓住 Fouad 就类似一个二分的过程,这个过程对于行和列是分别独立的。

因此我们就可以得到答案即为 log⁡2n+log⁡2min⁡{m−b+1,b} \log_2n+\log_2{\min\{m-b+1,b\}} 或log⁡2m+log⁡2min⁡{n−a+1,a} \log_2m+\log_2{\min\{n-a+1,a\}},对这两个答案取最小值即可,注意最后的答案要加 11,因为第一次删除也要计算。

代码

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=5e5+25;
const int inf=2e9;
int n,m,a,b;
inline void solve(){
    cin>>n>>m>>a>>b;
    int ans1=ceil(log2(m))+ceil(log2(min(n-a+1,a)));
    int ans2=ceil(log2(n))+ceil(log2(min(m-b+1,b)));
    cout<<min(ans1,ans2)+1<<'\n';
}
signed main(){
    srand(time(0));
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int T;
    cin>>T;
    while(T--)solve();
    return 0;
}
原文