---恢复内容开始---

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

Input
3 1
1 5 6
1 3
3
Output
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代替

综上,枚举长度2 (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);
}

L - Ray in the tube Gym - 101911L (暴力)的更多相关文章

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

    Ray in the tube 感觉是套路题.. 如果确定一个差值x我们如何取确定答案呢, 我们把a[ i ] -> a[ i ] % (2 * x), 把b[ i ] -> (b[ i ...

  2. CF 1041 F. Ray in the tube

    F. Ray in the tube 链接 题意: 有两条平行于x轴的直线A,B,每条直线上的某些位置有传感器.你需要确定A,B轴上任意两个整点位置$x_a$,$x_b$,使得一条光线沿$x_a→x_ ...

  3. Codeforces | CF1041F 【Ray in the tube】

    昨天晚上全机房集体开\(Div2\),因为人傻挂两次\(B\)题的我开场就\(rank2000+\dots qwq\)于是慌乱之中的我就开始胡乱看题(口胡),于是看了\(F\dots\)(全机房似乎也 ...

  4. Codeforces.1041F.Ray in the tube(思路)

    题目链接 \(Description\) 有两条平行于\(x\)轴的直线\(A,B\),每条直线上的某些位置有传感器.你需要确定\(A,B\)轴上任意两个整点位置\(x_A,x_B\),使得一条光线沿 ...

  5. The 2016 ACM-ICPC Asia China-Final L World Cup(深搜+回溯 暴力求解)

    题目分析: 对于A,B,C,D四支队伍,两两之间进行一场比赛,获胜得3分,平局得1分,失败不得分,现在对给出的四个队伍的得分,判断能否满足得到这种分数,且方案唯一输出yes,不唯一输出no,不可能则输 ...

  6. Ice Igloos Gym - 101480I (暴力技巧)

    Problem I: Ice Igloos \[ Time Limit: 10 s \quad Memory Limit: 512 MiB \] 题意 给出\(n\)个圆,给出每个圆的坐标\(x\). ...

  7. Codeforces Round #509 (Div. 2) F. Ray in the tube(思维)

    题目链接:http://codeforces.com/contest/1041/problem/F 题意:给出一根无限长的管子,在二维坐标上表示为y1 <= y <= y2,其中 y1 上 ...

  8. 【杂题】cf1041fF. Ray in the tube

    死于没有处理边界 题目描述 题目大意 在两面镜子上各选定一个整数位置的点 A 与 B,并从其中一个点向另一个射出一条光线,使得接收到光线的传感器数量尽可能的多.传感器不重叠. 题目分析 我们来初步考虑 ...

  9. Gym 101158D(暴力)

    题意:给定两个长度为N的字符串,1<=N<=4000,求满足字符串1中的某个区间所有的字母种类和个数都与字符串2中的某个区间相同最长的区间长度. 分析: 1.预处理每个串字母个数的前缀和. ...

随机推荐

  1. idea 去除xml文件sql语句背景色

    怎么看idea mapper.xml中写sql语句的那种屎黄屎黄背景颜色不好看 去除背景色 把这两项勾选去掉,然后 把这个背景勾选也去掉,最后 把这个勾选也去掉 另一种方式: 也可以使用这种方式 al ...

  2. 金9银10,分享几个重要的Android面试题

    说一下java多态的理解,以及接继承,和接口的理解 于哥在这里只讲多态,其他自己上网体会 对于多态的定义不同类的对象对统一函数做出不同对的响应或者动作.作用主要是消除类之间的耦合性,灵活性比较强,利于 ...

  3. struts2 过滤器和拦截器的区别和使用

    java web 过滤器和拦截器的区别和使用  1.1 什么是拦截器:      拦截器,在AOP(Aspect-Oriented Programming)中用于在某个方法或字段被访问之前,进行拦截然 ...

  4. Confluence 6 在 Apache 或者系统级别阻止垃圾

    如果一个垃圾发布机器人攻击你的 Confluence 站点,这些程序可能来自于同一个 IP 地址,或者是一个比较小范围的 IP 地址段.希望找到攻击者的 IP 地址,请参考 Apache access ...

  5. install memcached for ubuntu

    Memcached安装 1.先下载安装libevent 安装 libevent# tar zxvf libevent-1.4.9-stable.tar.gz# cd libevent-1.4.9-st ...

  6. EF Fluent API

    EntityTypeConfiguration 它可以为一个实体类,配置一个模型. Entity Framework 6 一次加载许多个 Fluent API 映射 如果对于许多实体有大量映射,则 O ...

  7. 解决ASP.NET MVC(post数据)Json请求太大,无法反序列化,而报【远程服务器返回错误: (500) 内部服务器错误】

    1. 修改web.config文件可以改变这个默认值(上传1个G) <configuration> <system.web> <httpRuntime maxReques ...

  8. [转] mongoose 之Shema

    总 之见到我写点啥简直是奇迹,由于现在喜欢上玩转node.js +mongoose,个人爱好,靠近前端的又是英文文档,苦逼得很,悟出来一个写一个吧.之前喜欢误打误撞,网上搜索一点解决一下问题,后来实在 ...

  9. 【bzoj4887】[Tjoi2017]可乐 矩阵乘法

    题解: 比较简单的一道题目 如果会倍增floyd这个就很显然的 每次转移看成乘上一个矩阵 另外自爆等同于连到一个特殊点,特殊点只能走自己 停留就是增加自环

  10. RN错误随笔 - Unable to resolve module 'AccessibilityInfo'

    错误信息:.React Native 运行报错:Unable to resolve module 'AccessibilityInfo' 可以看到在 异常的返回的JSON 结构中给出了推荐的解决方法 ...