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地点:北京国家会议中心
随机推荐
- Windows 忘记密码
能进入windows,以前保存的凭据,但是不知道啥. windows下进入cmd net user administrator abc123 这样可以重置密码
- Activity服务类-1 DynamicBpmnService服务类
这个服务是5.19版本后新增的一个服务,和RepositoryService的作用相似,都是与流程定义有关,但是却完全不同.从名字上来看是动态的BPMN服务,看里面的方法都是改变流程的相关属性.这个方 ...
- 程序员教程-9章-C程序设计
目录结构: 9.1 C语言基础 9.1.1 数据类型 1 基本数据类型 2 数组.字符数组与字符串 3 枚举类型 4 结构体.共用体和typedef 9.1.2 运算符与表达式 9.1.3 输入/输出 ...
- Java properties文件用法
package com.suyang.properties; import java.io.FileInputStream; import java.io.FileNotFoundException; ...
- Hibernate 的update语句性能详解
Hibernate 中如果直接使用 Session.update(Object o); 会把这个表中的所有字段更新一遍. 比如: view plaincopy to clipboardprint? p ...
- spring 中c3p0的优化配置
jdbc.properties driverClass=com.mysql.jdbc.Driver jdbcUrl=jdbc:mysql://localhost:3306/testdb user=ro ...
- zabbix3.2的server和zabbix-agent2.2怎么监控MySQL的办法
zabbix官方支持监控MySQL,但直接使用默认的模板是不可用的,还需要经过额外的设置才可以使用.如果只需要对mysql数据库做简单的监控,zabbix自带的模板完全能够满足要求:如果有更高的需求那 ...
- spring-boot PageHelper
分页插件PageHelper 参看了pagehelper-spring-boot,使用起来非常放方便,关于更多PageHelper可以点击https://github.com/pagehelper/M ...
- 安装RabbitMq-----windows
在官网download我们所需要的版本,安装rabbitMq需要erlang支持 rabbitMq :http://www.rabbitmq.com/download.html erlang :ht ...
- Android笔记:RelativeLayout
RelativeLayout 又称作相对布局,也是一种非常常用的布局.和 LinearLayout 的排列规则不同,RelativeLayout 显得更加随意一些,它可以通过相对定位的方式让控件出现在 ...