2018.07.12 atcoder Choosing Points(数学分析好题)
传送门
一句话题意:给出n,d1,d2" role="presentation" style="position: relative;">n,d1,d2n,d1,d2,需要求出n2" role="presentation" style="position: relative;">n2n2个点使得每两点之间的距离不为d1" role="presentation" style="position: relative;">d1d1或者d2" role="presentation" style="position: relative;">d2d2。
好吧这题第一眼直接暴力建图然后发现时间复杂度上天。显然不能暴力建图,看来d1,d2" role="presentation" style="position: relative;">d1,d2d1,d2应该具有一些奇妙的性质。
那么我们对d1,d2" role="presentation" style="position: relative;">d1,d2d1,d2来进行奇偶分析。
我们让d" role="presentation" style="position: relative;">dd表示两点之间的距离,a" role="presentation" style="position: relative;">aa表示两点之间的横坐标差,b" role="presentation" style="position: relative;">bb表示两点之间的纵坐标差。那么不合法的情况就满足d2=a2+b2" role="presentation" style="position: relative;">d2=a2+b2d2=a2+b2。好的讨论开始。
- 若d2" role="presentation" style="position: relative;">d2d2是一个奇数,显然a" role="presentation" style="position: relative;">aa和b" role="presentation" style="position: relative;">bb是一奇一偶的,这样的话就可以类似在棋盘上黑白染色一样,只染同一种颜色,然后任意两点间的距离的平方就都是偶数了。
- 若d2" role="presentation" style="position: relative;">d2d2 mod" role="presentation" style="position: relative;">modmod 4=2" role="presentation" style="position: relative;">4=24=2,可以推出a" role="presentation" style="position: relative;">aa和b" role="presentation" style="position: relative;">bb都是奇数,于是一排染色,一排不染色,这样的话任意a" role="presentation" style="position: relative;">aa,b" role="presentation" style="position: relative;">bb是一奇一偶或者两个偶。
最后一种情况,d2" role="presentation" style="position: relative;">d2d2 mod" role="presentation" style="position: relative;">modmod 4=0" role="presentation" style="position: relative;">4=04=0,这是最不好解决的情况,于是果断将每个2∗2" role="presentation" style="position: relative;">2∗22∗2的格子都缩小成一个格子,然后将d" role="presentation" style="position: relative;">dd缩小一半按前两种情况处理即可(反正题目保证可以找到n∗n" role="presentation" style="position: relative;">n∗nn∗n格子,因此只用缩小一次)。
代码如下:
#include<bits/stdc++.h>
#define eps 1e-7
using namespace std;
int n,d1,d2,cnt=0;
bool f[1005][1005];
inline void solve(int d){
int b=0;
while(!(d%4))d>>=2,++b;
if(d&1){
for(int i=0;i<(n<<1);++i)
for(int j=0;j<(n<<1);++j)
if(((i>>b)+(j>>b))&1)f[i][j]=true;
return;
}
for(int i=0;i<(n<<1);++i)
for(int j=0;j<(n<<1);++j)
if((i>>b)&1)f[i][j]=true;
}
int main(){
scanf("%d%d%d",&n,&d1,&d2);
solve(d1),solve(d2);
for(int i=0;i<(n<<1);++i)
for(int j=0;j<(n<<1);++j)
if(cnt<n*n&&!f[i][j])printf("%d %d\n",i,j),++cnt;
return 0;
}
2018.07.12 atcoder Choosing Points(数学分析好题)的更多相关文章
- 2018.07.12 atcoder Go Home(贪心)
传送门 题意简述:大家在数轴上生活,公司在 s. 班车送所有人回家,有 n 个住处,第 i 个位置在 xi,居住了 pi 的人. 保证 xi 互不相同. 大家⼀起投票向前还是向后,如果票数相同就固定向 ...
- China Internet Conference(2018.07.12)
中国互联网大会 时间:2018.07.12地点:北京国家会议中心
- 2018.07.20 atcoder Largest Smallest Cyclic Shift(贪心)
传送门 题意:给你x个a,y个b,z个c,显然这些字符可以拼成若干字符串,然后求这些字符串中最小表示法表示出来的最大的那一个. 解法:贪心思想,用multiset维护现在拼成的字串,每次取一个最小的和 ...
- 「AGC025D」 Choosing Points
「AGC025D」 Choosing Points 神仙构造题. 首先你会尝试暴力做,先随便选一个点,然后把当前能选得全选上,然后你发现这样样例都过不了. 然后我们可以这样考虑:你把距离为 \(\sq ...
- http://www.cnbc.com/2016/07/12/tensions-in-south-china-sea-to-persist-even-after-court-ruling.html
http://www.cnbc.com/2016/07/12/tensions-in-south-china-sea-to-persist-even-after-court-ruling.html T ...
- 2018年12月8日广州.NET微软技术俱乐部活动总结
吕毅写了一篇活动总结,写得很好!原文地址是:https://blog.walterlv.com/post/december-event-microsoft-technology-salon.html ...
- 2018.5.12 storm数据源kafka堆积
问题现象: storm代码依赖4个源数据topic,2018.5.12上午8点左右开始收到告警短信,源头的4个topic数据严重堆积. 排查: 1.查看stormUI, storm拓扑结构如下: 看现 ...
- Artificial Intelligence Computing Conference(2018.09.12)
时间:2018.09.12地点:北京国际饭店会议中心
- China Cloud Computing Conference(2018.07.24)
时间:2018.07.24地点:北京国家会议中心
随机推荐
- egret 配置设置
修改index.html的时候,要主要template文件夹下的web文件夹也有个index.html,两者控制的不一样 初始安装新建项目后调试这样的情况.重新安装引擎和下载egret安装包安装,默认 ...
- 7 python 模块间相互导入
python在不同层级目录import模块的方法 注意,在python3里,即使目录下没__int__.py文件也能创建成功,猜应该是解释器优化所致,但创建包还是要记得加上这个文件 吧. 1.模块的分 ...
- WDA-WebDynpro Demo & FPM Demo
Web Dynpro Demo package: SWDP_DEMO SWDP_TEST FPM Demo package: APB_FPM_DEMO APB_FPM_DEMO_SCENARIO
- Zuul超时问题,微服务响应超时,zuul进行熔断
天碰到了微服务响应超时问题,而且超时时间特别短,2秒就超时,zuul就走熔断了. 我采用zuul作为网关,根据不同的访问路径进行微服务的路由,譬如有个服务是user,我访问user服务的某个接口时,该 ...
- 树莓派3用create_ap变身无线AP
1.git clone https://github.com/oblique/create_ap.git2.cd create_ap3.sudo make install就这样安装好了4.接下来安装依 ...
- Centos 安装golang beego
刚开始用go和beego,真的还好多不懂~希望对看到的朋友有帮助~ 本人环境:centos 6.3x86_64 1.我在机器上创建了一个用户zww(useradd zww),登录zww(su zww) ...
- RabbitMq install on Centos
安装服务(root) erlang官方安装说明:https://www.erlang-solutions.com/resources/download.html step 1: 安装erlang的yu ...
- ng2-file-upload 使用记录
最近这两周一直在修bug,修的很是痛苦,不过痛苦也是件好事,不然每天都是在做同样的事情,没有什么挑战,工作多无聊呀! 是吧. 大致说一下背景吧: 这个项目是两年前开新项目,到现在一直还在开发中,一直不 ...
- ubuntu部署jenkins
https://www.cnblogs.com/lozz/p/9962316.html 1.安装 wget -q -O - https://pkg.jenkins.io/debian/jenkins- ...
- SQL dialect is not configured
在Idea中,xml配置文件报错:SQL dialect is not configured 解决方法如下: 在Idea中,在报错的地方按alt+enter,然后点击Generic配置dialect即 ...