CF1041F Ray in the tube
挂上Chester大神的解题报告
有一个思维跳跃的地方,就是不应该枚举所有的$B$点,而是应该在选定一个$A$点之后枚举距离计算。
然后我们发现枚举距离是$2^k$的长度就可以了,证明如下:
假如距离$d = 2^k$,那么对于每一个$A$点如果能被经过$a_p$的点弹到,需要满足$a_i\equiv a_p\ (Mod \ 2d)$,而对所有的$B$点,如果能被经过$a_p$的点弹到,需要满足$b_i + d \equiv a_p \ (Mod \ 2d)$。
那么对于一些其他的距离,我们的$d = 2^k$的距离一定可以计算到$td$所包含的点,所以这样子就足够了。
那么这样我们就可以枚举$d$然后去检验了,因为$d$的个数是$log(1e9)$个,然后用一个$map$记录一下同余的个数有几个更新答案即可。
时间复杂度$O(nlognlog1e9)$。
Code:
#include <cstdio>
#include <cstring>
#include <map>
using namespace std; const int N = 1e5 + ;
const int MaxN = (int)1e9; int n, m, ans = , a[N], b[N];
map <int, int> cnt; inline void read(int &X) {
X = ; char ch = ; int op = ;
for(; ch > '' || ch < ''; ch = getchar())
if(ch == '-') op = -;
for(; ch >= '' && ch <= ''; ch = getchar())
X = (X << ) + (X << ) + ch - ;
X *= op;
} inline void chkMax(int &x, int y) {
if(y > x) x = y;
} int main() {
int y;
read(n), read(y);
for(int i = ; i <= n; i++) read(a[i]);
read(m), read(y);
for(int i = ; i <= m; i++) read(b[i]); for(int d = ; d < MaxN; d <<= ) {
int P = d << ;
cnt.clear();
for(int i = ; i <= n; i++) cnt[a[i] & (P - )]++;
for(int i = ; i <= m; i++) cnt[(b[i] + d) & (P - )]++; for(map <int, int> :: iterator it = cnt.begin(); it != cnt.end(); ++it)
chkMax(ans, it -> second);
} printf("%d\n", ans);
return ;
}
CF1041F Ray in the tube的更多相关文章
- [CF1041F Ray in the tube][数学]
http://codeforces.com/contest/1041/problem/F 题目大意: 下边界有n个给定点,上边界有m个给定点,可以从任意一个点发出一条激光,激光碰到边界会反射 激光到达 ...
- CF1041F Ray in the tube构造_思维
不难发现起点必定是一个点. 每次间隔的距离一定是 2k2^k2k,关键就是要判断两点是否在同一跳跃距离上可被同时覆盖. 我们可以对上边进行 x1≡x_{1}\equivx1≡ x2mod(2∗dx) ...
- L - Ray in the tube Gym - 101911L (暴力)
---恢复内容开始--- You are given a tube which is reflective inside represented as two non-coinciding, but ...
- Codeforces 1041F Ray in the tube (看题解)
Ray in the tube 感觉是套路题.. 如果确定一个差值x我们如何取确定答案呢, 我们把a[ i ] -> a[ i ] % (2 * x), 把b[ i ] -> (b[ i ...
- CF 1041 F. Ray in the tube
F. Ray in the tube 链接 题意: 有两条平行于x轴的直线A,B,每条直线上的某些位置有传感器.你需要确定A,B轴上任意两个整点位置$x_a$,$x_b$,使得一条光线沿$x_a→x_ ...
- Codeforces | CF1041F 【Ray in the tube】
昨天晚上全机房集体开\(Div2\),因为人傻挂两次\(B\)题的我开场就\(rank2000+\dots qwq\)于是慌乱之中的我就开始胡乱看题(口胡),于是看了\(F\dots\)(全机房似乎也 ...
- Codeforces.1041F.Ray in the tube(思路)
题目链接 \(Description\) 有两条平行于\(x\)轴的直线\(A,B\),每条直线上的某些位置有传感器.你需要确定\(A,B\)轴上任意两个整点位置\(x_A,x_B\),使得一条光线沿 ...
- Codeforces Round #509 (Div. 2) F. Ray in the tube(思维)
题目链接:http://codeforces.com/contest/1041/problem/F 题意:给出一根无限长的管子,在二维坐标上表示为y1 <= y <= y2,其中 y1 上 ...
- 【杂题】cf1041fF. Ray in the tube
死于没有处理边界 题目描述 题目大意 在两面镜子上各选定一个整数位置的点 A 与 B,并从其中一个点向另一个射出一条光线,使得接收到光线的传感器数量尽可能的多.传感器不重叠. 题目分析 我们来初步考虑 ...
随机推荐
- systemverilog FAQ(zz)
1. What is clocking block? Ans: Clocking block can be declared using the keywords clocking and endcl ...
- python有哪些关键字?让他自己“吐”出来!
通过调用库来输出!for循环控制! 源代码: import keyword c = 0 for i in keyword.kwlist: print(i) c += 1 代码截图: 哈哈,关键字: F ...
- python内置方法补充bin
bin(x) 英文说明:Convert an integer number to a binary string. The result is a valid Python expression. I ...
- POJ 1611并查集
我发现以后写题要更细心,专心! #include<iostream>#include<algorithm>#include<stdio.h>#include< ...
- MAC下ssh免密码登录远程服务器
生成密钥.在终端下执行命令: ssh-keygen -t rsa 一路回车,各种提示按默认不要改,等待执行完毕.然后执行: ls ~/.ssh #可以看到两个密钥文件:id_rsa(私钥) id_rs ...
- MySQL- 用Navicat通过隧道连接到远程数据库
在企业中,为了安全地使用服务器,常常是用通过堡垒机才能连接到企业内部的服务器,当然也包括数据库. 于是我们时时需要通过堡垒机打隧道连到数据库,下面展示如何使用xshell用Navicat通过隧道连接到 ...
- 创建 CSS3 下拉菜单
1. [图片] 菜单效果 2. [代码]menu.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ...
- html基础学习(注意点)
浏览器会自动地在块级元素(<p><h1>)的前后添加空行 当显示页面时,浏览器会移除源代码中多余的空格和空行.所有连续的空格或空行都会被算作一个空格.需要注意的是,HTML 代 ...
- ListOperations
RedisOperations<K,V> getOperations() V index(K key, long index) V leftPop(K key) V leftPop( ...
- Centos7搭建Mysql-5.6.38,及主从复制。
Server1:192.168.1.189 (主) Server2:192.168.1.190 (从) 1.关闭默认的firewalld防火墙,安装iptables. systemctl disa ...