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数相等的个数. ...
随机推荐
- Java总复习内容
StringBuffer定义时需要用正确的方式 例如: StringBuffer xxx = new StringBuffer("雯雯是猪"); 使用StringBuffer的连接 ...
- [Cometoj#3 B]棋盘_状压dp
棋盘 题目链接:https://cometoj.com/contest/38/problem/B?problem_id=1535 数据范围:略. 题解: 因为行数特别小,所以$dp$的时候可以状压起来 ...
- 请给出一个Scala RDD的HelloWorld例子
[学习笔记]package comimport org.apache.spark.rdd.RDDimport org.apache.spark.SparkConfimport org.apache.s ...
- 【AtCoder】AGC004
AGC004 A - Divide a Cuboid 看哪一维是偶数,答案是0,否则是三个数两两组合相乘中最小的那个 #include <bits/stdc++.h> #define fi ...
- C#读写操作app.config中的数据
<?xml version="1.0" encoding="utf-8" ?> <configuration> <connecti ...
- error LNK2001: unresolved external symbol __imp__closesocket@4
环境:Visual C++6.0 问题:链接错误 描述: Linking... NetSrv.obj : error LNK2001: unresolvedexternal symbol __imp_ ...
- js图片压缩上传
最近公司的移动产品相约app要做一次活动,涉及到图片上传,图片又不能太大,不然用户体验太差,必须先压缩再上传,所以用到了html5的canvas和FileReader,代码先上,小弟前端经验不足,代码 ...
- python基础(十)--函数进阶
嵌套函数 >>> graphic = '三角形' >>> def chang(): graphic = '正方形' def chang1(): #内部嵌套的函数命名 ...
- 安装gcc过程中遇到相互依赖的问题
在离线安装gcc的时候需要安装一些包,但是在安装 glibc-common glibc遇到一个很恶心的问题,这两个包相互依赖. 经查询才发现需要一起安装这两个依赖包.真是有趣的很 rpm -iv ...
- 怎样写一个 "Hello, World!"
第一步: 打开浏览器, 按 F12 键或 Ctrl + Shift + J. 注意: 1. 打开的这个界面是浏览器的开发者工具界面. 2. 顶部有许多Tab栏, 如: Elements / Co ...