Problem Statement

A hexagonal cell is represented as $(i,j)$ with two integers $i$ and $j$.

Cell $(i,j)$ is adjacent to the following six cells:

  • $(i-1,j-1)$
  • $(i-1,j)$
  • $(i,j-1)$
  • $(i,j+1)$
  • $(i+1,j)$
  • $(i+1,j+1)$

Let us define the distance between two cells $X$ and $Y$ by the minimum number of moves required to travel from cell $X$ to cell $Y$ by repeatedly moving to an adjacent cell.

For example, the distance between cells $(0,0)$ and $(1,1)$ is $1$, and the distance between cells $(2,1)$ and $(-1,-1)$ is $3$.

You are given $N$ cells $(X_1,Y_1),\ldots,(X_N,Y_N)$.

How many ways are there to choose one or more from these $N$ cells so that the distance between any two of the chosen cells is at most $D$?

Find the count modulo $998244353$.

Constraints

  • $1 \leq N \leq 300$
  • $-10^9\leq X_i,Y_i \leq 10^9$
  • $1\leq D \leq 10^{10}$
  • $(X_i,Y_i)$ are pairwise distinct.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

$N$ $D$
$X_1$ $Y_1$
$\vdots$
$X_N$ $Y_N$

Output

Print the answer.


Sample Input 1

3 1
0 0
0 1
1 0

Sample Output 1

5

There are five possible sets of the chosen cells: $\{(0,0)\},\{(0,1)\},\{(1,0)\},\{(0,0),(0,1)\}$, and $\{(0,0),(1,0)\}$.


Sample Input 2

9 1
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2

Sample Output 2

33

Sample Input 3

5 10000000000
314159265 358979323
846264338 -327950288
-419716939 937510582
-97494459 -230781640
628620899 862803482

先考虑怎样算出最短路。如果 $x1< x2,y1< y2$ 时,从 $(x1,y1)$ 到 $(x2,y2)$的方案是先不停的走 $(x+1,y+1)$,使得 $x1=x2$ 或者 $y1=y2$,然后再慢慢走。所以最短路长度为 $\max(x2-x1,y2-y1)$。 $x1>x2,y1>y2$ 时同理,最短路长度不妨写成 $\max(|x2-x1|,|y2-y1|)$

反之,如果 \(x1<x2,y1>y2\),并不能走 \((x+1,y-1)\),所以只能一步一步走。最短路长度为 \(x2-x1+y1-y2\),最短路为 \(x1>x2,y1<y2\) 时同理,最短路长度为 \(|x2-x1+y1-y2|\)。

两个结论想办法整合一下,设 \(a=\max(|x2-x1|,|y2-y1|)\),\(b=|x1-y1+x2-y2|\)。会发现非常的巧,如果 \(x1<x2,y1<y2\) 时,\(a>b\)。如果 \(x1<x2,y1>y2\) 时, \(a<b\)。反过来同理,所以其实两个点 \((x1,y1)\) 和 \((x2,y2)\) 的距离为 \(\max(|x2-x1|,|y2-y1|,|(x1-y1)+(x2-y2)|)\)

然后就非常套路了。枚举 \(x\),\(y\),\(x-y\) 的最小值(枚举的是点),并钦定这些点必选。然后看有多少个点在他们围出来的范围内。如果在的话,统计。设有 \(cnt\) 个,那么答案会增加 \(2^{cnt}\) 个。这样的方案,由于他们的最小值是不同的,所以不会重复统计。不过注意要把 \(x\) 相同的, \(y\) 相同的, \(x-y\)相同的强行钦定一个顺序。可以使用离散化处理。

但是如果枚举完暴力去找所有在范围中的数,复杂度 \(O(n^4)\)。但我们可以使用双指针加入和删除去统计就好了。具体而言,枚举了 \(x\) 的最小值和 \(y\) 的最小值后,把点按 \(x-y\) 从小到大加入就行了。

#include<bits/stdc++.h>
using namespace std;
const int N=305,P=998244353;
int n,ans,pw[N],lshx[N],lshy[N],fx[N],fy[N];
long long d;
struct node{
int x,y;
bool operator<(const node&n)const{
return lshx[x]-lshy[y]<lshx[n.x]-lshy[n.y];
}
}t[N];
int can(int u,int x,int y)
{
return t[u].x>=t[x].x&&lshx[t[u].x]<=lshx[t[x].x]+d&&t[u].y>=t[y].y&&lshy[t[u].y]<=lshy[t[y].y]+d;
}
int main()
{
scanf("%d%lld",&n,&d);
for(int i=pw[0]=1;i<=n;i++)
pw[i]=pw[i-1]*2%P;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&t[i].x,&t[i].y);
lshx[i]=t[i].x,lshy[i]=t[i].y;
}
sort(lshx+1,lshx+n+1);
sort(lshy+1,lshy+n+1);
for(int i=1;i<=n;i++)
{
t[i].x=lower_bound(lshx+1,lshx+n+1,t[i].x)-lshx;
fx[t[i].x]++,t[i].x+=fx[t[i].x]-1;
t[i].y=lower_bound(lshy+1,lshy+n+1,t[i].y)-lshy;
fy[t[i].y]++,t[i].y+=fy[t[i].y]-1;
}
sort(t+1,t+n+1);
// for(int i=1;i<=n;i++)
// printf("%d %d\n",t[i].x,t[i].y);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(!can(j,i,j)||!can(i,i,j))
continue;
int r=0,s=0;
for(int k=1;k<=n;k++)
{
if(!can(k,i,j))
continue;
int z=lshx[t[k].x]-lshy[t[k].y];
while(r<n)
{
if(!can(r+1,i,j))
++r;
else if(lshx[t[r+1].x]-lshy[t[r+1].y]<=z+d)
++r,++s;
else
break;
}
if(k<=i&&k<=j&&z+d>=lshx[t[i].x]-lshy[t[i].y]&&z+d>=lshx[t[j].x]-lshy[t[j].y])
{
int t=s;
if(i==j&&j==k)
t--;
else if(i==j||j==k||i==k)
t-=2;
else
t-=3;
(ans+=pw[t])%=P;
// printf("%d %d %d %d %d\n",i,j,k,ans,t);
}
--s;
}
}
}
printf("%d",ans) ;
}

[ABC280G] Do Use Hexagon Grid 2的更多相关文章

  1. x264源代码简单分析:宏块分析(Analysis)部分-帧间宏块(Inter)

    ===================================================== H.264源代码分析文章列表: [编码 - x264] x264源代码简单分析:概述 x26 ...

  2. ExtJS 4.2 Grid组件的单元格合并

    ExtJS 4.2 Grid组件本身并没有提供单元格合并功能,需要自己实现这个功能. 目录 1. 原理 2. 多列合并 3. 代码与在线演示 1. 原理 1.1 HTML代码分析 首先创建一个Grid ...

  3. WPF中Grid实现网格,表格样式通用类

    /// <summary> /// 给Grid添加边框线 /// </summary> /// <param name="grid"></ ...

  4. 在 Windows Phone 中,为 Grid 添加 Tilt 效果

    在 Windows Phone 中,Tilt 效果是比较经典的效果,我们可以很简单的为按钮等控件添加这样的效果(使用 Windows Phone Toolkit 的Tilt 效果),但是,如果我们想要 ...

  5. wpf 列表、菜单 收起与展开,通过Grid DoubleAnimation或者Expander实现

    菜单收缩有很多种方法具体如何实现还是看个人想法: 第一种通过后台控制收起与展开: 效果图: 代码 : <Grid> <Grid.ColumnDefinitions> <C ...

  6. Sencha ExtJS 6 Widget Grid 入门

    最近由于业务需要,研究了一下Sencha ExtJS 6 ,虽然UI和性能上据相关资料说都有提升,但是用起来确实不太顺手,而且用Sencha cmd工具进行测试和发布,很多内部细节都是隐藏的,出了问题 ...

  7. WPF CheckBox样式 ScrollViewer样式 WrapPanel、StackPanel、Grid布局

    本节讲述布局,顺带加点样式给大家看看~单纯学布局,肯定是枯燥的~哈哈 那如上界面,该如何设计呢? 1.一些布局元素经常用到.Grid StackPanel Canvas WrapPanel等.如上这种 ...

  8. [转]ExtJS Grid 分页时保持选中的简单实现方法

    原文地址 :http://www.qeefee.com/article/ext-grid-keep-paging-selection ExtJS中经常要用到分页和选择,但是当选择遇到分页的时候,杯具就 ...

  9. [转]extjs grid的Ext.grid.CheckboxSelectionModel默认选中解决方法

    原文地址:http://379548695.iteye.com/blog/1167234 grid的复选框定义如下:   var sm = new Ext.grid.CheckboxSelection ...

  10. EXTJS中grid的数据特殊显示,不同窗口的数据传递

    //EXTJS中grid的数据特殊显示renderer : function(value, metaData, record, rowIndex, colIndex, store, view) { v ...

随机推荐

  1. 每日一库:gosec

    gosec 是一个用于在 Go 代码中查找安全问题的开源工具,它可以帮助发现可能的漏洞和潜在的安全风险.以下是关于 gosec 的详细介绍: 1. 工具概述: gosec 是一个静态分析工具,用于扫描 ...

  2. 【pandas小技巧】--DataFrame的显示参数

    我们在jupyter notebook中使用pandas显示DataFrame的数据时,由于屏幕大小,或者数据量大小的原因,常常会觉得显示出来的表格不是特别符合预期. 这时,就需要调整pandas显示 ...

  3. 三维模型OSGB格式轻量化的跨平台兼容性技术分析

    三维模型OSGB格式轻量化的跨平台兼容性技术分析 在三维模型应用中,OSGB格式轻量化处理是一种常见的技术手段,可以通过数据压缩.简化.滤波等操作,降低三维模型数据的存储空间和传输带宽需求,提高应用程 ...

  4. 使用Java Xpath 爬取某易云歌曲

    本文使用Java xpath 爬取某易云歌曲,并下载至本地. 代码仅用于个人学习使用,欢迎各位大佬提出建议. 1.添加依赖 <dependency> <groupId>cn.w ...

  5. 用shell命令绘制三角形

    本文旨在通过几个经典的图案来练习shell编程,涉及知识点:for循环,大小比较,基本的数学公式计算,echo小技巧.update:2019-10-17 10:13:54 初次绘制 $ for ((l ...

  6. [面向对象] 魔术方法 (__set, __get, __unset, __isset)

    __set, __get,__isset, __unset 是面向对象里用来友操作的魔术方法.  先看看使用方法 echo $类->属性;  //取不存在属性或私有保护属性时,  以下方法被调用 ...

  7. Java实践项目 - 商品分类

    Smiling & Weeping ---- 好想回到那个拉钩许诺的年代 1.1商品分类的思路:一次性查询三级分类 (一级为美味麒麟榜,二级为闭眼入,第三级为商品) 优点:只需要一次查询,根据 ...

  8. Mysql进击篇-存储引擎、索引、sql优化、视图、锁、innoDb、管理

    1.存储引擎 (1)连接层 最上层是一些客户端和连接服务,主要完成一些类似于连接处理,授权认证.以及相关的安全方案,服务器也会为安全接入的每个客户端验证它所具有的操作权限 (2)服务层 第二层架构主要 ...

  9. Matlab 实现连续PID环节与标记系统-3dB点

    Matlab 实现连续PID环节 连续PID环节传递函数: \[\frac{O(s)}{I(s)} = K_P \cdot \left( 1 + \frac{K_{I}}{s} + K_D\cdot ...

  10. Ubuntu 22.04上安装docker方法及oracle 11g方法

    1.切换到管理员登录 ubt2204@ubt2204-Virtual-Machine:~/database$ su Password: 2.执行安装docker命令 root@ubt2204-Virt ...