Codeforces Round #509 (Div. 2) F. Ray in the tube(思维)
题目链接:http://codeforces.com/contest/1041/problem/F
题意:给出一根无限长的管子,在二维坐标上表示为y1 <= y <= y2,其中 y1 上与 n 个点,y2 上有 m 个点,问在 y1 和 y2 上各选一个点,从其中一个点出发射到另外一个点并无限反射下去,可以触碰到 y1 和 y2 上的点和最大为多少。
题解:考虑射出去的线打到对面板上所需要走的距离dd,假设出发点为0,则打在自己这边上的点的坐标为{0,2d,4d,6d,8d,...}{0,2d,4d,6d,8d,...},打在对面板上的则是{d,3d,5d,7d,9d,...}{d,3d,5d,7d,9d,...}。若将距离改为k⋅d,则两个点集分别为{0,2kd,4kd,6kd,8kd,...}{0,2kd,4kd,6kd,8kd,...},{kd,3kd,5kd,7kd,9kd,...}{kd,3kd,5kd,7kd,9kd,...},可以发现若k为奇数,两个集合中的点都只会减少不会增加,kk为偶数时则有存在增减的情况,因此设k=2^l一定是最优的。
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LL __int128
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pi acos(-1)
#define pii pair<int,int>
#define pb push_back
const int INF = 0x3f3f3f3f;
const double eps = 1e-;
const int MAXN = 1e5 + ;
const int MAXM = 2e6 + ;
const ll mod = 1e9 + ; int a[MAXN], b[MAXN];
map<ll,int>mp; int main()
{
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int n,m,y;
scanf("%d%d",&n,&y);
for(int i = ; i < n; i++) scanf("%d",&a[i]);
scanf("%d%d",&m,&y);
for(int i = ; i < m; i++) scanf("%d",&b[i]);
int ans = ;
ll d = , dd = ;
for(int i = ; i <= ; i++) {
mp.clear();
dd <<= ;
for(int j = ; j < n; j++) mp[a[j] % dd]++;
for(int j = ; j < m; j++) mp[(b[j] + d) % dd]++;
for(auto it : mp) ans = max(ans, it.second);
d <<= ;
}
printf("%d\n",ans);
return ;
}
Codeforces Round #509 (Div. 2) F. Ray in the tube(思维)的更多相关文章
- Codeforces Round #485 (Div. 2) F. AND Graph
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...
- Codeforces Round #486 (Div. 3) F. Rain and Umbrellas
Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- Codeforces Round #501 (Div. 3) F. Bracket Substring
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...
- Codeforces Round #499 (Div. 1) F. Tree
Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...
- Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)
Problem Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Descripti ...
- Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)
题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的 ...
- Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)
题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...
- Codeforces Round #325 (Div. 2) F. Lizard Era: Beginning meet in the mid
F. Lizard Era: Beginning Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)
题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数. ...
随机推荐
- spring security中Authority、Role的区别
最近在研究spring security时,大概研究了一下Authority.Role之间到底有什么本质的区别. 如果你使用的是hasRole方法来判断你的登录用户是否有权限访问某个接口,那么你初始化 ...
- sql数据库的基础语句
1, 创建数据库 create database database-name 2, 删除数据库 drop database dbname 3, 备份sql server 创建 备份数据的device ...
- 【AtCoder】ARC064
ARC064 C - Boxes and Candies 先把每个盒子都消到x 然后从前往后推,要求第二个的上界是x-前一个 因为我们要求靠后的那个尽量小,会对后面的修改影响尽量小 #include ...
- 题解 CF546C 【Soldier and Cards】
思路 是一道水题,可以用队列+模拟来写,注意不要拿完队列中的元素! 代码 #include<iostream> #include<cstdio> #include<que ...
- MySQL修改和查看表类型
//修改表类型alter table verify_code engine = MEMORY;//查看表类型show create table verify_code;
- windows 安装K8s 简易教程
1. 先安装 chocolatey https://chocolatey.org/install administrator 运行 命令: @"%SystemRoot%\System32\W ...
- 某康x电视去广告
开启adb 信源选择进入模拟电视 然后按菜单键输入2008 找到其他选项,进去把adb root打开 删除对应广告视频(短暂方法) 可以下载tvbox,利用文件管理功能 进入/data/misc/ko ...
- HTML Ueditor加载空白问题
问题描述 Ueditor打开时加载不出内容 原因分析 Ueditor重复加载时,会存在缓存问题 Ueditor采用异步加载方式,所以数据获取和赋值要写在Ueditor异步回调里 解决方案 UE.del ...
- JavaScript随机验证码
利用canvas制作一个随机验证码: 1.clearRect:context.clearRect(x,y,width,height);清空给定矩形内的指定像素 2.fillStyle:设置画笔的颜色 ...
- JS原生实现照片抽奖
HTML表格标记实现九宫格,放入九张图片.利用CSS的滤镜属性控制图片的透明度.Javascript实现抽奖和中奖. 可以做为教师上课,随机抽取回答问题的同学,使学生感受到随机的公平性,简单有趣! 点 ...