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地点:北京国家会议中心
随机推荐
- 5.Struts2配置形式,覆盖
转自:https://wenku.baidu.com/view/84fa86ae360cba1aa911da02.html 下面以对struts.i18n.encoding=UTF-8的配置为例进行说 ...
- eclipse中添加aptana插件(html.css.js自动提示)
一.关于aptana aptana是一款很不错的插件,本人主要用于安装此类插件,在eclipse中用于编辑javascript代码,html代码,和css代码的,因为其有自动纠错功能,当然安装后的问题 ...
- eclipse 和 javaClass
eclipse 如果设置为 Build automaticaly 会自动对当前的类进行编译,放在项目下的bin文件夹下. 1. 如果此Class有错,则编译后的Class不能用,里面仅仅写会抛出异常代 ...
- Haskell语言学习笔记(31)ListT
Control.Monad.Trans.List 标准库中的 ListT 的实现由于有 bug,已经被废弃. list-t 模块 这里使用 list-t 模块中的 ListT. list-t 模块需要 ...
- 自然对数e(转)
e表示增长的极限 e=limx→+∞ (1+1/x)^x≍2.71828 假设,一根竹子,第一天是1米,第二天长了1米,然后这根柱子的长度变成了2米.相当于 (1+1/1)^1.上面这个假设,如果仔细 ...
- 数据预处理之独热编码(One-Hot Encoding)(转载)
问题由来 在很多机器学习任务中,特征并不总是连续值,而有可能是分类值. 例如,考虑一下的三个特征: ["male", "female"] ["from ...
- struts2标签类别
要在jsp中使用Struts2的标志,先要指明标志的引入.通过jsp的代码的顶部加入以下的代码: <%@taglib prefix="s" uri="/struts ...
- ios web input 内边阴影
ios网页中,默认input上部有阴影,去除方法: -webkit-appearance: none;
- Maven国内镜像-阿里云
国外的maven下载速度堪忧,大部分国内网络访问都很慢国内的阿里云同样提供了maven的文件镜像使用:1.在maven的setting.xml加入下段代码即可使用阿里云的maven镜像 <mir ...
- Linux跑火车,提升趣味性
實現跑火車[可陶冶情操,愉悦心情]##下载yum源[root@localhost ~]# wget http://mirror.centos.org/centos/7/extras/x86_64/P ...