[AGC025D]Choosing Points

题目大意:

输⼊\(n(n\le300),d_1,d_2\),你要找到\(n^2\)个整点\((x,y)\)满⾜\(0\le x,y<2n\)。并且找到的任意两个点距离,既不是\(\sqrt{d_1}\),也不是\(\sqrt{d_2}\)。

思路:

所有距离为\(\sqrt{d_1}\)的点连边,可以得到一个⼆分图。\(d_2\)同理。注意到满足\(a^2+b^2=d\)的\((a,b)\)只有\(\mathcal O(n)\)个,可以得到\(\mathcal O(n^3)\)的二分图染色做法。

源代码:

#include<cmath>
#include<cstdio>
#include<cctype>
#include<vector>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
const int N=600;
int n,d1,d2,col[2][N*N];
std::vector<std::pair<int,int>> v[2];
inline int id(const int &x,const int &y) {
return x*N+y;
}
inline bool check(const int &x) {
return 0<=x&&x<n*2;
}
void dfs(const int &x,const int &t) {
const int i=x/N,j=x%N;
for(auto &d:v[t]) {
const int nx=i+d.first,ny=j+d.second;
if(!check(nx)||!check(ny)) continue;
const int y=id(i+d.first,j+d.second);
if(!col[t][y]) {
col[t][y]=col[t][x]==1?2:1;
dfs(y,t);
}
}
}
int main() {
n=getint(),d1=getint(),d2=getint();
for(register int i=0;i<=d1;i++) {
const int j=sqrt(d1-i*i);
if(i*i+j*j!=d1) continue;
v[0].emplace_back(std::make_pair(i,j));
v[0].emplace_back(std::make_pair(-i,j));
v[0].emplace_back(std::make_pair(i,-j));
v[0].emplace_back(std::make_pair(-i,-j));
}
for(register int i=0;i<=d2;i++) {
const int j=sqrt(d2-i*i);
if(i*i+j*j!=d2) continue;
v[1].emplace_back(std::make_pair(i,j));
v[1].emplace_back(std::make_pair(-i,j));
v[1].emplace_back(std::make_pair(i,-j));
v[1].emplace_back(std::make_pair(-i,-j));
}
for(register int i=0;i<n*2;i++) {
for(register int j=0;j<n*2;j++) {
if(!col[0][id(i,j)]) {
col[0][id(i,j)]=1;
dfs(id(i,j),0);
}
if(!col[1][id(i,j)]) {
col[1][id(i,j)]=1;
dfs(id(i,j),1);
}
}
}
for(register int i=0,cnt=0;i<n*2;i++) {
for(register int j=0;j<n*2;j++) {
if(col[0][id(i,j)]==1&&col[1][id(i,j)]==1) {
printf("%d %d\n",i,j);
if(++cnt==n*n) return 0;
}
}
}
}

[AGC025D]Choosing Points的更多相关文章

  1. 「AGC025D」 Choosing Points

    「AGC025D」 Choosing Points 神仙构造题. 首先你会尝试暴力做,先随便选一个点,然后把当前能选得全选上,然后你发现这样样例都过不了. 然后我们可以这样考虑:你把距离为 \(\sq ...

  2. 2018.07.12 atcoder Choosing Points(数学分析好题)

    传送门 一句话题意:给出n,d1,d2" role="presentation" style="position: relative;">n,d ...

  3. AtCoder Grand Contest 025 Problem D - Choosing Points

    题目大意:输入$n,d1,d2$,你要找到$n^2$个整点 x, y 满足$0 \leqslant x, y<2n$.并且找到的任意两个点距离,既不是$\sqrt{d1}$,也不是 $\sqrt ...

  4. atcoder题目合集(持续更新中)

    Choosing Points 数学 Integers on a Tree 构造 Leftmost Ball 计数dp+组合数学 Painting Graphs with AtCoDeer tarja ...

  5. 【AtCoder】AGC025题解

    A - Digits Sum 枚举即可 代码 #include <bits/stdc++.h> #define fi first #define se second #define pii ...

  6. AGC025简要题解

    AGC025简要题解 B RGB Coloring 一道简单题,枚举即可. C Interval Game 考虑可以进行的操作只有两种,即左拉和右拉,连续进行两次相同的操作是没有用的. 左拉时肯定会选 ...

  7. 有理数的稠密性(The rational points are dense on the number axis.)

    每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.

  8. [LeetCode] Max Points on a Line 共线点个数

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

  9. CF219D. Choosing Capital for Treeland [树形DP]

    D. Choosing Capital for Treeland time limit per test 3 seconds memory limit per test 256 megabytes i ...

随机推荐

  1. 玩一下易语言 "和"字有多种读音,注定了它的重要性!!

    变量名 类型 静态 数组 备注 拼音 文本型   0   测试的汉字 文本型       有几种发音 整数型       i 整数型       测试用的汉字 = “和” 有几种发音 = 取发音数目 ...

  2. new操作符的内部运行解析

    在加上new操作符,我们就能完成传统面向对象的class + new的方式创建对象,在Javascript中,我们将这类方式成为Pseudoclassical. 基于上面的例子,我们执行如下代码   ...

  3. ie8下trim失效

    1.ie8下使用trim失效 trim可以除去字符串两侧的空白字符,但ie8并不支持 2.解决方案 String.prototype.trim = function () { return this ...

  4. [bzoj1070] 修车

    这周学习了费用流,就写了几题.其中有一题就是bzoj上的修车,看起来很丧,交了6次都是除了样例全wa(事实证明样例说明不了什么,还会误导你……). 题目大意:有m个技术人员n辆车,一个技术人员只能同时 ...

  5. centos7安装libvirt支持xen

    另外还有一个非常棒的用法 假如我要执行iostat这个命令来查看CPU与存储设备状态,可是执行却发现没有这个命令 于是执行yum install iostat,结果说找不到该软件,使用下面的办法可以解 ...

  6. Linux内核空间内存申请函数kmalloc、kzalloc、vmalloc的区别【转】

    转自:http://www.th7.cn/system/lin/201606/167750.shtml 我们都知道在用户空间动态申请内存用的函数是 malloc(),这个函数在各种操作系统上的使用是一 ...

  7. 文字顺时针旋转90度(纵向)&古诗词排版

    1.文字旋转90度 width: 100px; height: 200px; line-height: 100px; text-align: center; writing-mode: vertica ...

  8. vim的各种tips

    centos系统,修改vim的配置文件 /etc/vimrc 添加如下内容: 1) 打开 vimrc ,添加以下语句来使得语法高亮显示: syntax on 2) 如果此时语法还是没有高亮显示,那么在 ...

  9. 应用程序有bug崩溃重启的案例2

    ------解决思路----------------------另外做一个服务或者程序定时监控系统进程.程序奔溃的话,都会在入口函数出现异常处理一下winform可以有两个事件来捕获主线程异常和线程异 ...

  10. Leetcode 之Binary Tree Inorder Traversal(43)

    树的中序遍历.先不断压入左结点至末尾,再访问,再压入右结点.注意和先序遍历的比较 vector<int> inorderTraversal(TreeNode *root) { vector ...