死于没有处理边界

题目描述

题目大意

在两面镜子上各选定一个整数位置的点 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的更多相关文章

  1. Codeforces 1041F Ray in the tube (看题解)

    Ray in the tube 感觉是套路题.. 如果确定一个差值x我们如何取确定答案呢, 我们把a[ i ] -> a[ i ] % (2 * x), 把b[ i ] -> (b[ i ...

  2. L - Ray in the tube Gym - 101911L (暴力)

    ---恢复内容开始--- You are given a tube which is reflective inside represented as two non-coinciding, but ...

  3. CF 1041 F. Ray in the tube

    F. Ray in the tube 链接 题意: 有两条平行于x轴的直线A,B,每条直线上的某些位置有传感器.你需要确定A,B轴上任意两个整点位置$x_a$,$x_b$,使得一条光线沿$x_a→x_ ...

  4. 正睿OI DAY3 杂题选讲

    正睿OI DAY3 杂题选讲 CodeChef MSTONES n个点,可以构造7条直线使得每个点都在直线上,找到一条直线使得上面的点最多 随机化算法,check到答案的概率为\(1/49\) \(n ...

  5. dp杂题(根据个人进度选更)

    ----19.7.30 今天又开了一个新专题,dp杂题,我依旧按照之前一样,这一个专题更在一起,根据个人进度选更题目; dp就是动态规划,本人认为,动态规划的核心就是dp状态的设立以及dp转移方程的推 ...

  6. wangkoala杂题总集(根据个人进度选更)

    CQOI2014 数三角形 首先一看题,先容斥一波,求出网格内选三个点所有的情况,也就是C(n*m,3);然后抛出行里三点共线的方案数:C(n,3)*m; 同理就有列中三点共线的方案数:n*C(m,3 ...

  7. 2019暑期金华集训 Day6 杂题选讲

    自闭集训 Day6 杂题选讲 CF round 469 E 发现一个数不可能取两次,因为1,1不如1,2. 发现不可能选一个数的正负,因为1,-1不如1,-2. hihoCoder挑战赛29 D 设\ ...

  8. Atcoder&CodeForces杂题11.7

    Preface 又自己开了场CF/Atcoder杂题,比昨天的稍难,题目也更有趣了 昨晚炉石检验血统果然是非洲人... 希望这是给NOIP2018续点rp吧 A.CF1068C-Colored Roo ...

  9. Codeforces 杂题集 2.0

      记录一些没有写在其他随笔中的 Codeforces 杂题, 以 Problemset 题号排序   1326D2 - Prefix-Suffix Palindrome (Hard version) ...

随机推荐

  1. speedtest-cli 命令

    speedtest-cli是一个使用python编写的命令行脚本,通过调用speedtest.net测试上下行的接口来完成速度测试,项目地址:https://github.com/sivel/spee ...

  2. 第七周课程总结&实验报告(五)

    实验四 类的继承 实验目的 理解抽象类与接口的使用: 了解包的作用,掌握包的设计方法. 实验要求 掌握使用抽象类的方法. 掌握使用系统接口的技术和创建自定义接口的方法. 了解 Java 系统包的结构. ...

  3. Java判断指定日期是否为工作日

    Java判断指定日期是否为工作日 转自:https://www.jianshu.com/p/966659492f2f 转:https://www.jianshu.com/p/05ccb5783f65转 ...

  4. 理解twisted中的reactor和deferred(二)

    Deferred可以添加多个回调函数,每个回调函数的结果作为下一个回调函数的参数 代码实例(可在pycharm中运行,摘自 https://twistedmatrix.com/documents/cu ...

  5. SQLite基础-4.数据定义语言(DDL)

    目录 一.创建数据库 1. 创建方式 2. 数据库命名规范 二. 创建表 1. 基本用法 2. 数据表命名规范 3. 字段命名规范 三. 删除表 一.创建数据库 1. 创建方式 在第二章中我们讲了如何 ...

  6. Treasure Island(两遍dfs)-- Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises)

    题意:https://codeforc.es/contest/1214/problem/D 给你一个n*m的图,每次可以往右或者往下走,问你使(1,1)不能到(n,m)最少要放多少 ‘ # ’ . 思 ...

  7. print格式化输出(format)

    一. print格式化输出,以及使用format控制 字符串的格式化方法分为两种,分别为占位符(%)和format方式.占位符方式在Python2.x中用的比较广泛,随着Python3.x的使用越来越 ...

  8. 并不对劲的CF1239B&C&D Programming Task in the Train to Catowice City

    CF1239B The World Is Just a Programming Task 题目描述 定义一个括号序列s是优秀的,当且仅当它是以下几种情况的一种: 1.|s|=0 2.s='('+t+' ...

  9. Validator自动验证与手动验证

    自动: public JResult projectAdd(@Valid Project project, BindingResult result) {Map<String,Object> ...

  10. stuff拼接字符串

    stuff stuff(param1,startIndex,length,param2) 说明:将param1中自startIndex(SQL中都是从1开始,而非0)起,删除length个字符,然后用 ...