---恢复内容开始---
You are given a tube which is reflective inside represented as two non-coinciding, but parallel to OxOx lines. Each line has some special integer points — positions of sensors on sides of the tube.
You are going to emit a laser ray in the tube. To do so, you have to choose two integer points AA and BB on the first and the second line respectively (coordinates can be negative): the point AA is responsible for the position of the laser, and the point BB — for the direction of the laser ray. The laser ray is a ray starting at AA and directed at BB which will reflect from the sides of the tube (it doesn't matter if there are any sensors at a reflection point or not). A sensor will only register the ray if the ray hits exactly at the position of the sensor.
Examples of laser rays. Note that image contains two examples. The 3 sensors (denoted by black bold points on the tube sides) will register the blue ray but only 2 will register the red.
Calculate the maximum number of sensors which can register your ray if you choose points AA and BB on the first and the second lines respectively.
Input
The first line contains two integers n and y1 (1≤n≤1051≤n≤105 , 0≤y1≤1090≤y1≤109 ) — number of sensors on the first line and its yy coordinate.
The second line contains nn integers a1,a2,…,an (0≤ai≤1090≤ai≤109 ) — xx coordinates of the sensors on the first line in the ascending order.
The third line contains two integers m and y2 (1≤m≤1051≤m≤105 , y1<y2≤109y1<y2≤109 ) — number of sensors on the second line and its yy coordinate.
The fourth line contains mm integers b1,b2,…,bm(0≤bi≤1090≤bi≤109 ) — xx coordinates of the sensors on the second line in the ascending order.
Output
Print the only integer — the maximum number of sensors which can register the ray.
Example
3 1
1 5 6
1 3
3
3
Note
One of the solutions illustrated on the image by pair A2 and B2 .
题意:
给出n个点在y1的水平线上,给出m个点在y2的水平面上,有一道光线可以在这两个水平线中折射,并且从任意位置开始,求对多可以经过多少了点
思路:我们可以枚举光的折射长度,也就是从下界到上界再回到下界的长度,可以发现这样两界面的高度y可以忽略
另外,我们不可能从1枚举1e9。
①显然,任何奇数步长可以有步长1取代
关键就是偶数步长,任何偶数长度可以有 2n * m (n>=1,m为奇数), 因为任何偶数都可以被2整除,那么当商为偶数时,我们可以将商提出2,将2乘上2,这样仍是2的幂次,然后直到商就变成了奇数
②偶数可以用2n代替
综上,枚举长度2n (0 <= n <= log(1e9)),
然后我们可以知道,对于一个定长度的步长,然后界面上的点取模2倍步长,余数相同的就是在一条折射线上的,对于另一界面,不能直接取模2倍步长,应该加上步长再取模2倍步长
#include<bits/stdc++.h>
using namespace std;
int n,m;
const int maxn = 1e5+;
int a[maxn];
int b[maxn];
int tmp[maxn<<]; int main()
{
int val;
scanf("%d%d",&n,&val);
for(int i=;i<=n;i++)scanf("%d",&a[i]);
scanf("%d%d",&m,&val);
for(int i=;i<=m;i++)scanf("%d",&b[i]);
int ans = ;
int tot = n+m;
tmp[tot+] = 2e9+;
for(int step = ;step <= int(1e9);step<<=)
{
int mod = step<<;
for(int i=;i<=n;i++)tmp[i] = a[i]%mod;
for(int i=;i<=m;i++)tmp[i+n] = (b[i]+step)%mod;
sort(tmp+,tmp++tot);
for(int i=,last=;i<=tot;i++)
{
if(tmp[i+] != tmp[i])
{
ans = max(ans,i+-last);
last = i+;
}
}
}
printf("%d\n",ans);
}