Codeforces 1371E2 - Asterism (二分)

Posted limil

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces 1371E2 - Asterism (二分)相关的知识,希望对你有一定的参考价值。

Description

思路

cf题解中合法的x的处于一段连续区间不太明白。在知道这个前提下,将E1的代码改成二分即可。
有空再补回来。

#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <iomanip>
#include <cctype>
 
#define endl ‘
‘
#define IOS std::ios::sync_with_stdio(0);
#define FILE freopen("..//data_generator//in.txt","r",stdin),freopen("res.txt","w",stdout)
#define FI freopen("..//data_generator//in.txt","r",stdin)
#define FO freopen("res.txt","w",stdout)
#define pb push_back
#define mp make_pair
#define seteps(N) fixed << setprecision(N) 
 
typedef long long ll;
using namespace std;
/*-----------------------------------------------------------------*/
 
#define INF 0x3f3f3f3f
const int N = 3e5 + 10;
const double eps = 1e-8;
 
int arr[N];
vector<int> ans;
 
bool check(int x, int p, int n){
    bool ok = true;
    for(int i = 0; i < n; i++) {
        int num = min(i + 1, i + 1 + (x - arr[i]));
        if(num <= 0 || !(num % p)) {
            ok = false;
            break;
        } 
    }
    return ok;
}
 
int main() {
    IOS;
    int n, p;
    cin >> n >> p;
    int mx = -INF;
    int mi = INF;
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    sort(arr, arr + n);
    for(int i = 0; i < n; i++) {
        mx = max(arr[i], mx);
        mi = min(i + 1 - arr[i], mi);
    }
    int s = max(0, 0 - mi + 1);
    int e = mx;
    int l = s, r = e;
    while(l <= r) {
        int mid = (l + r) / 2;
        if(check(mid, p, n)) {
            l = mid + 1;
        } else {
            r = mid - 1;
        }
    }
    e = r;
    if(s > e) {
        cout << 0 << endl;
    } else {
        cout << e - s + 1 << endl;
        for(int x = s; x <= e; x++) cout << x << " ";
    }
}

以上是关于Codeforces 1371E2 - Asterism (二分)的主要内容,如果未能解决你的问题,请参考以下文章

文字识别领域经典论文:ASTER

我们是冠军 恭喜ASTER.Y夺得2021极限冲层赛第二赛季全球总冠军

Aster守护者全球护理奖现已开始接受世界各地护士的申请,奖金高达25万美元

銆愯浆銆慔Base涓璟ookeeper锛孯egionServer锛孧aster锛孋lient涔嬮棿鍏崇郴

HTB-Bastard

相伴十六载,讲讲我和数据仓库的故事