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

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 11 5 61 33

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+5;
int a[maxn];
int b[maxn];
int tmp[maxn<<1];int main()
{int val;scanf("%d%d",&n,&val);for(int i=1;i<=n;i++)scanf("%d",&a[i]);scanf("%d%d",&m,&val);for(int i=1;i<=m;i++)scanf("%d",&b[i]);int ans = 2;int tot = n+m;tmp[tot+1] = 2e9+1;for(int step = 1;step <= int(1e9);step<<=1){int mod = step<<1;for(int i=1;i<=n;i++)tmp[i] = a[i]%mod;for(int i=1;i<=m;i++)tmp[i+n] = (b[i]+step)%mod;sort(tmp+1,tmp+1+tot);for(int i=1,last=1;i<=tot;i++){if(tmp[i+1] != tmp[i]){ans = max(ans,i+1-last);last = i+1;}}}printf("%d\n",ans);
}

View Code

转载于:https://www.cnblogs.com/iwannabe/p/10580849.html

L - Ray in the tube Gym - 101911L (暴力)相关推荐

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

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

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

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

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

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

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

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

  5. cf1041F. Ray in the tube

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

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

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

  7. Ray 分布式简单教程(2)

    本教程将介绍 Ray 的核心功能. Ray 提供了 Python 和 Java API.要在 Python 中使用 Ray,首先使用以下命令安装 Ray:pip install ray.要在 Java ...

  8. 暴力破解zip压缩包

    1:Windows下使用工具archpr工具进行破解 bandzip专业版也可以破解 2:python脚本破解 import zipfilef = open('password.txt', 'w') ...

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

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

最新文章

  1. Nature:科研PUA太严重,过半博士后打算逃离
  2. ppt流程图字体太小_论文答辩PPT攻略,答辩季你准备好了吗?
  3. 微信小程序首页index.js获取不到app.js中动态设置的globalData的原因以及解决方法
  4. silverlight学习布局之:布局stackpanel
  5. 阅读笔记一——java高并发的性能优化
  6. Ubuntu 9.10下Nvidia官方最新190.42显卡驱动安装
  7. 简单编译安装Apache
  8. 实现生成小学四则运算练习题
  9. linux open 头文件_linux下通过共享内存和mmap实现进程间通讯
  10. break是python合法标识符,Python笔记——break的注意事项
  11. Python编程高手之路——第三章:数据类型
  12. 开课吧Java课堂之什么是搜索字符串
  13. PDF在线预览 (flexpaper+swftools+saveaspdfandxps)
  14. mysql触发器更新自己表_mysql触发器实例:更新表数据之前触发
  15. 结构化思维(Structured Thinking)
  16. 数字信号处理基础----采样定理
  17. 快递单号中的派件时效该怎么查?
  18. C++:Leetcode-滑动窗口-904.水果成篮
  19. elment文件上传 展示点击下载
  20. soloV2保姆级教程(含环境配置,训练自己的数据集,代码逻辑分析等。能踩得坑都踩了....)更新ing

热门文章

  1. python开发框架——Django基础知识(七)
  2. 基于科大讯飞语音识别demo(离线)
  3. 【STM32 .Net MF开发板学习-02】GPIO测试
  4. windows电脑cmd命令查看网卡的物理地址(mac地址)
  5. 【二维前缀和】304. 二维区域和检索 - 矩阵不可变
  6. python自动化看什么书_python自动化测试书籍
  7. Win10连接上了wifi,但显示Internet无网络访问权限的解决方法
  8. Linux服务器之内存过高解决思路
  9. Tk应用程序:密码输入框
  10. 计网PPT 第六章 应用层