Codeforces 1041F Ray in the tube (看题解)

Ray in the tube

感觉是套路题。。

如果确定一个差值x我们如何取确定答案呢, 我们把a[ i ] -> a[ i ] % (2 * x), 把b[ i ] -> (b[ i ] + k) % (2 * x),

值相同的都能同时射到。

同时我们能发现, 对于一个差值x如果它有奇数因子, 把它除掉之后会更优, 所以我们要check的x只有2的幂次。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long

using namespace std;

const int N = 2e5 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1);

map<int, int> Map;

int n, m, y, ans, a[N], b[N];
int main() {
    scanf("%d%d", &n, &y);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    scanf("%d%d", &m, &y);
    for(int i = 1; i <= m; i++) scanf("%d", &b[i]);
    for(int k = 1; k < 1e9 + 7; k *= 2) {
        Map.clear();
        for(int i = 1; i <= n; i++) Map[a[i] % (2 * k)]++;
        for(int i = 1; i <= m; i++) Map[(b[i] + k) % (2 * k)]++;
        for(auto& t : Map) ans = max(ans, t.se);
    }
    ans = max(ans, 2);
    printf("%d\n", ans);
    return 0;
}

/*
*/

猜你喜欢

转载自www.cnblogs.com/CJLHY/p/10425389.html