当前位置:网站首页>Niuke 2021 summer training 6-h-hopping rabbit
Niuke 2021 summer training 6-h-hopping rabbit
2022-07-18 05:00:00 【yl-9】
Cattle guest 2021 Summer training 6-H-Hopping Rabbit
The question
There is... On the plane n n n A rectangle , Given d d d, Need to find a place ( x , y ) (x,y) (x,y), Make all ( x + k d , y + k d ) (x+kd,y+kd) (x+kd,y+kd) Do not fall in the rectangle
Answer key
Pre knowledge : Scan line
Because the positions that can be reached are repeated , We move all rectangles to ( 0 , 0 ) (0,0) (0,0) To ( d , d ) (d,d) (d,d) Join in range , If there are uncovered points in the final range , Then this point can be used as the answer . Rectangle Union , Use scanning line .
Move to ( d , d ) (d,d) (d,d) It may be disassembled into 1 , 2 , 4 1,2,4 1,2,4 A rectangle 

At the same time, because the title gives a rectangle , And the little rabbit is at the midpoint of the rectangle , So rectangular x 2 x_2 x2 It can be stepped on , Let's move the edge to the midpoint , x 1 , x 2 x_1,x_2 x1,x2 It becomes x 1 , x 2 − 1 x_1,x_2-1 x1,x2−1, y y y Empathy .
Other things are explained in the code
Code
#include<bits/stdc++.h>
#define PR pair<int,int>
#define Fi first
#define Se second
#define Mp make_pair
#define Pb push_back
using namespace std;
const int N=1e5+9;
int n,d;
int t[N*4],vis[N*4];
vector<PR>e1,e2,s1[N],s2[N];
void Change(int u,int l,int r,int y1,int y2,int flag)
{
if(y1<=l&&r<=y2)
{
t[u]+=flag;
vis[u]+=flag; //vis Indicates the interval l~r Number of matrices
return;
}
int mid=(l+r)/2;
if(y1<=mid) Change(u*2,l,mid,y1,y2,flag);
if(y2>mid) Change(u*2+1,mid+1,r,y1,y2,flag);
t[u]=min(t[u*2],t[u*2+1])+vis[u];
}
int Ask(int u,int l,int r)
{
if(l==r) return l;
int mid=(l+r)/2;
if(t[u]==t[u*2]+vis[u]) return Ask(u*2,l,mid); //23 Line code
else return Ask(u*2+1,mid+1,r);
}
int main()
{
cin>>n>>d;
int P=(1<<30)/d*d; // Less than or equal to 1<<30 Maximum d Multiple
for(int i=1;i<=n;i++)
{
int x1,x2,y1,y2;
cin>>x1>>y1>>x2>>y2;
x1+=P; y1+=P; x2+=P; y2+=P; // add d The multiple of is guaranteed to be positive
e1.clear(); e2.clear();
if(x2-x1>=d) e1.Pb(Mp(0,d-1)); // Fill up d
else if(x1%d<=(x2-1)%d) e1.Pb(Mp(x1%d,(x2-1)%d)); //x Not more than d
else // More than d, Divided into two groups. x
{
e1.Pb(Mp(x1%d,d-1));
e1.Pb(Mp(0,(x2-1)%d));
}
if(y2-y1>=d) e2.Pb(Mp(0,d-1));
else if(y1%d<=(y2-1)%d) e2.Pb(Mp(y1%d,(y2-1)%d));
else
{
e2.Pb(Mp(y1%d,d-1));
e2.Pb(Mp(0,(y2-1)%d));
}
// Only split into a rectangle : One x, One y
// Split it into two : One x Two y, Or two x One
// Split into four : Two x, Two y
for(auto j:e1) // parallel y The scanning line of the camera
{
for(auto k:e2)
{
s1[j.Fi].Pb(k); // The previous one y by +1
s2[j.Se+1].Pb(k); //j.Fi~j.Se by +1,x=j.Se+1 Subtract
}
}
}
for(int i=0;i<d;i++) // Scan line
{
for(auto j:s1[i])
Change(1,0,d-1,j.Fi,j.Se,1);
for(auto j:s2[i])
Change(1,0,d-1,j.Fi,j.Se,-1);
if(!t[1]) // if t1==0, It means that there is no line covering 0~d-1 And one thing is 0
{
printf("YES\n%d %d\n",i,Ask(1,0,d-1));
return 0;
}
}
printf("NO\n");
return 0;
}
边栏推荐
- openstack登陆dashboard提示认证发生错误
- sentinel1.8.4 持久化nacos配置
- A 59 year old doctor studying in the United States, today received his fifth listed company
- tensor与Img的互相转换
- 【rasterio】geojson矢量栅格化
- u-boot之顶层Makefile分析(三)
- C#一个方法返回多个值建议收藏
- 【luogu P3175】按位或(min-max容斥)(高维前缀和 / FWT)
- LeetCode_ Sliding window_ Binary search_ Medium_ 713. Subarray with product less than k
- Start of u-boot S analysis (I)
猜你喜欢

u-boot之start.S分析(一)

元宇宙带火的VR市场,字节也才摸到一点边

Cyclic multi-Variate Function for Self-Supervised Image Denoising by Disentangling Noise from Image

清晰的理解大端和小端

华为云Stack南向开放框架,帮助生态伙伴高效入云

Clear understanding of big end and small end

什么是服务器内存?如何选择服务器内存?

动作捕捉协助中国电力科学研究院建立边云协同电力自主巡检系统

Construction and compilation of uboot environment

u-boot之start.S分析(二)
随机推荐
Luogu p4113 [heoi2012] flower picking solution
WPS关闭烦人广告
u-boot之顶层Makefile分析(二)之config.mk文件的生成
EN 1090-1 structural members for steel and aluminum construction - CE certification
EN 1155建筑五金件摆动门开启装置—CE认证
牛客2021暑期训练5-B-Boxes
普歌-码上鸿鹄团队-Vscode 代码格式化整理
Redis04:Redis的3种特殊的数据类型
如何在Apache中禁用sslv3
Link script of u-boot
Generate XML file of VOC dataset
openstack登陆dashboard提示认证发生错误
C#基本概念列举说明建议收藏
网络安全网格概念以及特点简单普及
59岁留美博士, 今天收获第五家上市公司
四、Explain 性能分析
log4j.properties 日志详解
SN6多光谱和SAR数据融合
Create a list, add the strings "a", "B", "C", "d" and "d" in turn, and print the contents of the set, then remove all the strings "d" in the list, and print its contents again
EN 1317-5道路约束系统产品—CE认证