【杂题】cf1041fF. Ray in the tube
死于没有处理边界
题目描述

题目大意
在两面镜子上各选定一个整数位置的点 A 与 B,并从其中一个点向另一个射出一条光线,使得接收到光线的传感器数量尽可能的多。传感器不重叠。
题目分析
我们来初步考虑一下答案路径的形式。

1.$i$为奇数:那么我们以步长$1$去走,不仅一定经过最优答案的路径,还有可能会走过其他传感器。因此步长$1$囊括了所有$i$为奇数的情况。
2.$i$为偶数:沿用上续思路,用步长$2$去试试?发现$path=4k+2$.也就是说还剩下所有距离$4k$的点走不到.如果接着用步长$8$呢?那么$path=8k+4$.
这意味着我们枚举$\log_22\times10^9$次步长,每次$n\log_2n$验证,就覆盖了所有走法。
死于没有处理$ans=2$的初值。
#pragma GCC optimize(2)
#include<bits/stdc++.h>
typedef long long ll;
const int maxn = ;
const int Det = ; int n,m,h,ans;
int a[maxn],b[maxn],s[maxn],t[maxn],sap[maxn]; int read()
{
char ch = getchar();
int num = , fl = ;
for (; !isdigit(ch); ch=getchar())
if (ch=='-') fl = -;
for (; isdigit(ch); ch=getchar())
num = (num<<)+(num<<)+ch-;
return num*fl;
}
void Gap(ll x)
{
// printf("x:%lld\n",x);
for (int i=; i<=n; i++) s[i] = a[i]%x;
for (int i=; i<=m; i++) t[i] = (1ll*b[i]+x/)%x;
std::sort(s+, s+n+);
std::sort(t+, t+m+);
for (int L=,R=; L<=n; ++L)
{
int cnta = , cntb = ;
for (; s[L+]==s[L]&&L<n; ++L) ++cnta;
for (; t[R] < s[L]&&R < m; ++R);
for (; (t[R]==s[L])&&R<=m; ++R) ++cntb;
ans = std::max(ans, cnta+cntb);
}
for (int i=; i<=m; i++) sap[i] = t[i];
for (int i=; i<=n; i++) t[i] = s[i];
for (int i=; i<=m; i++) s[i] = sap[i];
std::swap(n, m);
for (int L=,R=; L<=n; ++L)
{
int cnta = , cntb = ;
for (; s[L+]==s[L]&&L<n; ++L) ++cnta;
for (; t[R] < s[L]&&R < m; ++R);
for (; (t[R]==s[L])&&R<=m; ++R) ++cntb;
ans = std::max(ans, cnta+cntb);
}
std::swap(n, m);
}
int main()
{
freopen("mirror.in","r",stdin);
freopen("mirror.out","w",stdout);
n = read(), m = read(), h = read(), ans = ;
for (int i=; i<=n; i++) a[i] = read()+Det;
for (int i=; i<=m; i++) b[i] = read()+Det;
for (ll i=; i<=2ll*Det; i*=2ll) Gap(i);
printf("%d\n",ans);
return ;
}
cf上还有一种比我 快4倍 的分治做法,除了没怎么看懂都挺好的。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
inline char gc(){
static char buf[],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,,,stdin),p1==p2)?EOF:*p1++;
}
#define pc putchar
#define fi first
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
#define rank __RANK
inline ll read(){
register ll x=,f=;register char c=gc();
for(;!isdigit(c);c=gc())if(c=='-')f=-;
for(;isdigit(c);c=gc())x=(x<<)+(x<<)+(c^);
return x*f;
}
#define rd read
void write(ll x){if(x<)x=-x,pc('-');if(x>=)write(x/);putchar(x%+'');}
void writeln(ll x){write(x);puts("");}
const int maxn = 1e5+;
int a[][maxn],tmp[][maxn];
int n,m;
int ans = ;
int cnt[][];
#define max(a,b) ((a) < (b) ? (b) : (a))
inline void solve(int l0,int r0,int l1,int r1){
if((l0>r0) || (l1>r1)){
if(l0<=r0) ans = max(ans,r0-l0+);
if(l1<=r1) ans = max(ans,r1-l1+);
return ;
}
if(a[][r0]==&&a[][r1]==) return ;
Rep(i,l0,r0) tmp[][i] = a[][i];
Rep(i,l1,r1) tmp[][i] = a[][i];
cnt[][]=cnt[][]=cnt[][]=cnt[][]=;
Rep(i,l0,r0)
if(i==l0 || a[][i] != a[][i-])
cnt[][a[][i]&]++; Rep(i,l1,r1)if(i==l1 || a[][i] != a[][i-])cnt[][a[][i]&]++;
ans = max(max(ans,cnt[][]+cnt[][]),cnt[][]+cnt[][]);
int L0 = l0,R0 = r0;
Rep(i,l0,r0)if(tmp[][i]&)a[][L0++] = tmp[][i]>>;
Dep(i,r0,l0)if(!(tmp[][i]&))a[][R0--] = tmp[][i]>>;
int L1 = l1,R1 = r1;
Rep(i,l1,r1)if(tmp[][i]&) a[][L1++] = tmp[][i]>>;
Dep(i,r1,l1)if(!(tmp[][i]&))a[][R1--] = tmp[][i]>>;
solve(l0,L0-,l1,L1-);
solve(R0+,r0,R1+,r1);
}
int main(){
n = rd();rd();
ans = ;
Rep(i,,n) a[][i]=rd();
sort(a[]+,a[]++n);
m = rd();rd();
Rep(i,,m) a[][i]=rd();
sort(a[]+,a[]++m);
if(n==&&m==&&a[][]==a[][]){
puts("");
return ;
}
solve(,n,,m);
writeln(ans);
return ;
}
END
【杂题】cf1041fF. Ray in the tube的更多相关文章
- Codeforces 1041F Ray in the tube (看题解)
Ray in the tube 感觉是套路题.. 如果确定一个差值x我们如何取确定答案呢, 我们把a[ i ] -> a[ i ] % (2 * x), 把b[ i ] -> (b[ i ...
- L - Ray in the tube Gym - 101911L (暴力)
---恢复内容开始--- You are given a tube which is reflective inside represented as two non-coinciding, but ...
- CF 1041 F. Ray in the tube
F. Ray in the tube 链接 题意: 有两条平行于x轴的直线A,B,每条直线上的某些位置有传感器.你需要确定A,B轴上任意两个整点位置$x_a$,$x_b$,使得一条光线沿$x_a→x_ ...
- 正睿OI DAY3 杂题选讲
正睿OI DAY3 杂题选讲 CodeChef MSTONES n个点,可以构造7条直线使得每个点都在直线上,找到一条直线使得上面的点最多 随机化算法,check到答案的概率为\(1/49\) \(n ...
- dp杂题(根据个人进度选更)
----19.7.30 今天又开了一个新专题,dp杂题,我依旧按照之前一样,这一个专题更在一起,根据个人进度选更题目; dp就是动态规划,本人认为,动态规划的核心就是dp状态的设立以及dp转移方程的推 ...
- wangkoala杂题总集(根据个人进度选更)
CQOI2014 数三角形 首先一看题,先容斥一波,求出网格内选三个点所有的情况,也就是C(n*m,3);然后抛出行里三点共线的方案数:C(n,3)*m; 同理就有列中三点共线的方案数:n*C(m,3 ...
- 2019暑期金华集训 Day6 杂题选讲
自闭集训 Day6 杂题选讲 CF round 469 E 发现一个数不可能取两次,因为1,1不如1,2. 发现不可能选一个数的正负,因为1,-1不如1,-2. hihoCoder挑战赛29 D 设\ ...
- Atcoder&CodeForces杂题11.7
Preface 又自己开了场CF/Atcoder杂题,比昨天的稍难,题目也更有趣了 昨晚炉石检验血统果然是非洲人... 希望这是给NOIP2018续点rp吧 A.CF1068C-Colored Roo ...
- Codeforces 杂题集 2.0
记录一些没有写在其他随笔中的 Codeforces 杂题, 以 Problemset 题号排序 1326D2 - Prefix-Suffix Palindrome (Hard version) ...
随机推荐
- PHP学习(4)——数组的使用
1.数组的概念 数组就是一个用来存储一系列变量值的命名区域. 每个数组元素有一个相关的索引(也成为关键字),它可以用来访问元素. PHP允许间隔性地使用数字或字符串作为数组的索引. 2.数字索引数组 ...
- zping ping包工具20180605.exe测试版
链接: https://pan.baidu.com/s/1WB3BZn0r9n4DRU_8bNC65g 提取码: mybi zping的第一个exe版本由于未对兼容性进行测试,使用python3.6编 ...
- 网络流三大算法【邻接矩阵+邻接表】POJ1273
网络流的基本概念跟算法原理我是在以下两篇博客里看懂的,写的非常好. http://www.cnblogs.com/ZJUT-jiangnan/p/3632525.html http://www.cnb ...
- autossh
LDAP:用old HK login SSH转发:/root/.nat_rules/opay-new root@ldap opay-new]# cat maria1-dw-60000 #!/bin/b ...
- [转帖]传输层安全协议TLS 1.3 RFC 8446使互联网更快、更安全
传输层安全协议TLS 1.3 RFC 8446使互联网更快.更安全 2018-08-12 11:38:19作者:LINUX人稿源:开源社区 https://ywnz.com/linuxyffq/261 ...
- cxLookupComboBox控件的应用
1.Properties-DropDownListStyle:下拉列表的模式, 里面有三个值:lsEditList: lsEditFixedList lsFixedList 2.Head ...
- 【问题】【编程环境】fatal error: security/pam_appl.h
[问题] 今天在docker中基于centos镜像的容器编译gogs遇到错误 似乎缺少库文件 [解决] yum -y install pam-devel
- Codeforces 1244D. Paint the Tree
传送门 首先如果某个点的度数大于 $2$ 那么显然无解 然后考虑点的度数小于等于 $2$ 的情况 发现其实是一条链 一旦确定了链开头的两个点,后面的点的颜色都可以通过之前的点推出 所以直接枚举即可 # ...
- Sql Server--如何自动备份数据
下面我来讲一下如何通过维护计划来实现完整备份+差异备份: (1)在SSMS的对象资源管理器中右击“维护计划”,选择“维护计划向导”,系统将弹出向导窗口,如图: 这里向导已经告诉我们维护计划到底能够干什 ...
- pycharm2017.3.3永久激活(转载)
pycharm是很强大的开发工具,但是每次注册着实让人头疼.网络上很多注册码.注册服务器等等.但都只是一年或者不能用:为次有如下解决方案.亲测有效!!! 如果想让pycharm永久被激活,比如截止日到 ...