原题链接:http://codeforces.com/contest/1041/problem/F

Ray in the tube

You are given a tube which is reflective inside represented as two non-coinciding, but parallel to OxOxOx 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 AAA and BBB on the first and the second line respectively (coordinates can be negative): the point AAA is responsible for the position of the laser, and the point BBB — for the direction of the laser ray. The laser ray is a ray starting at AAA and directed at BBB 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 333 sensors (denoted by black bold points on the tube sides) will register the blue ray but only 222will register the red.

Calculate the maximum number of sensors which can register your ray if you choose points AAA and BBB on the first and the second lines respectively.

Input

The first line contains two integers nnn and y1(1≤n≤105,0≤y1≤109)y_1 (1≤n≤10^5, 0≤y_1≤10^9)y1​(1≤n≤105,0≤y1​≤109) — number of sensors on the first line and its yyy coordinate.

The second line contains nnn integers a1,a2,⋯ ,an(0≤ai≤109)a_1,a_2,\cdots,a_n (0≤a_i≤10^9)a1​,a2​,⋯,an​(0≤ai​≤109) — xxx coordinates of the sensors on the first line in the ascending order.

The third line contains two integers mmm and y2(1≤m≤105,y1&lt;y2≤109)y_2 (1≤m≤10^5, y_1&lt;y_2≤10^9)y2​(1≤m≤105,y1​<y2​≤109) — number of sensors on the second line and its yyy coordinate.

The fourth line contains mmm integers b1,b2,⋯&ThinSpace;,bm(0≤bi≤109)b_1,b_2,\cdots,b_m (0≤b_i≤10^9)b1​,b2​,⋯,bm​(0≤bi​≤109) — xxx 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 A2A_2A2​ and B2B_2B2​.

题解

如果在实数域做的话,我们可以从一个无限接近于90∘90^\circ90∘的角度发出射线,这样整个管子都是射线岂不是很棒?

然而放到整数域的话,我们能做到的最极限角度就是步长为111了,这样由于反射问题,在同一侧管壁上射线就是两个点两个点的跳的,导致有一半的整点达不到:

谁能填这些空呢?我们试试步长为222的射线:

发现只填了一半的空,再试试步长为333的,发现被步长为111完虐,而步长为444的射线又可以填掉一半的空。。。以此类推,可以发现只有步长为2n2^n2n的射线可以到达一些其他线到不了的点,除此之外的步长都严格劣于2n2^n2n(即其他步长能到达的点集都会被一个步长为2n2^n2n的射线能到达的点集严格包含)。

那么我们就只需要枚举步长为2n2^n2n的射线了,对于同侧的点,只要modmodmod二倍步长同余就说明在同一射线上,对于异侧的点则需要先加上步长再取模。

由于模数较大而n,mn,mn,m很小,可以用mapmapmap来统计。

代码

学习了一波读入姿势,感觉很强。

#include<bits/stdc++.h>
using namespace std;
const int M=1e5+5;
int up[M],down[M],ans=2,n,m;
map<int,int>mp;
void in(){scanf("%d%*d",&n);for(int i=1;i<=n;++i)scanf("%d",&up[i]);scanf("%d%*d",&m);for(int i=1;i<=m;++i)scanf("%d",&down[i]);}
void ac()
{for(int d=2;d<=1e9;d<<=1){mp.clear();for(int i=1;i<=n;++i)++mp[up[i]%d],ans=max(ans,mp[up[i]%d]);for(int i=1;i<=m;++i)++mp[(down[i]+(d>>1))%d],ans=max(ans,mp[(down[i]+(d>>1))%d]);}printf("%d",ans);
}
int main(){in();ac();}

CF1041F Ray in the tube相关推荐

  1. CF1041F Ray in the tube构造_思维

    不难发现起点必定是一个点. 每次间隔的距离一定是 2k2^k2k,关键就是要判断两点是否在同一跳跃距离上可被同时覆盖. 我们可以对上边进行 x1≡x_{1}\equivx1​≡ x2mod(2∗dx) ...

  2. cf1041F. Ray in the tube

    链接 点击跳转 题解 稍微瞎在纸上画一画,会发现一个问题,假设线端在横轴上的投影长度为www,那么w=3w=3w=3的情况可以被w=1w=1w=1的情况替代 如下: 但是w=4w=4w=4的情况却不行 ...

  3. L. Ray in the tube(思维暴力)

    L. Ray in the tube(思维&暴力) 思路:思维+暴力. 记:A,BA,BA,B的横坐标距离为xxx. 1.当xxx为奇数时,显然x=1x=1x=1包含所有奇数的情况. 2.当x ...

  4. L - Ray in the tube Gym - 101911L (暴力)

    ---恢复内容开始--- You are given a tube which is reflective inside represented as two non-coinciding, but ...

  5. Problem G Ray in the tube(思维)

    https://codeforces.com/gym/101911/problem/L 题意 在二维坐标系中给出两个直线 y = a, y = b.在这两条直线上分别有n个和m个传感器,可以任意选两个 ...

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

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

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

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

  8. CF刷题——2500难度的几道题

    1.D. Beautiful numbers 题意:Beautiful Numbers定义为这个数能整除它的所有位上非零整数.问[l,r]之间的Beautiful Numbers的个数. 数位 DP: ...

  9. 光电效应的历史:爱因斯坦与莱纳德之间的争斗

    光电效应的历史 Photoelectric Effect History: A Battle of Einstein vs. Lenard Kathy老师讲述的有趣科学历史 01 光电效应 一.原文字 ...

  10. 做题记录 To 2019.2.13

    2019-01-18 4543: [POI2014]Hotel加强版:长链剖分+树形dp. 3653: 谈笑风生:dfs序+主席树. POJ 3678 Katu Puzzle:2-sat问题,给n个变 ...

最新文章

  1. C++ Primer英文版(第5版)
  2. VS2010重构学习总结
  3. opencart mail.php,如何修改OpenCart系统发信邮箱模板
  4. c语言不允许对数组的大小做动态定义,数组,C语言程序设计课件,与中南大学出版社教材相配套.ppt...
  5. Java读取xml数据
  6. linux是32还是64位,如何看linux是32位还是64位
  7. npm 安装 chromedriver 失败的解决办法
  8. C学习杂记(五)形参实参笔试题
  9. 检测范围_论文检测系统的检测范围有哪些
  10. mysql 查询语句 过滤_MySQL全面瓦解7:查询的过滤条件
  11. 码农不得不做的P图辨识能力
  12. 【绪论】——声呐概述
  13. mv强制覆盖 shell_生产力工具:shell 与 Bash 脚本
  14. 【转】ASP.NET Core WebApi使用Swagger生成api说明文档看这篇就够了
  15. 如何通过svg代码还原图片_如何通过nginx反向代理来调试代码?
  16. 由一维数组创建小根堆
  17. 小程序 switch 自定义_微信小程序自定义组件问题一:获取组件DOM元素
  18. PHP - Smarty模板引擎 - Download下载 - 2.6.22
  19. FPGA入门必看资源
  20. fedora安装字体

热门文章

  1. 二元函数极值问题:最小二乘法
  2. 联想微型计算机beta2,联想上网本升级IdeaPad S10-2
  3. 探测内网c段、外网某网站(ip)的网络服务存活状态
  4. VUE2.0 elemenui-ui 2.0.X 封装 省市区三级
  5. 解析json对象出现$ref: $.list[0]的解决办法
  6. 如何从数据库(实体提供者)读取安全用户(转自http://wiki.jikexueyuan.com/project/symfony-cookbook/entity-provider.html)...
  7. [POJ2796]Feel Good
  8. PostgreSQL学习手册(函数和操作符三)
  9. spring框架类加载顺顺序 并 在spring启动后查询数据库加载到容器内
  10. Spring框架入门程序:获取Bean的三种方式