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

Posted cjlhy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
", ans);
    return 0;
}

/*
*/

 

以上是关于Codeforces 1041F Ray in the tube (看题解)的主要内容,如果未能解决你的问题,请参考以下文章

codeforces781D Axel and Marston in Bitland

Codeforces997D Cycles in product FFT树形DP

光追起步 Ray Tracing in One Weekend

CodeForces - 1498D Bananas in a Microwave(思维+dp)

CodeForces914 E. Palindromes in a Tree 点分治

Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics)