[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. Python模块学习 - openpyxl

    openpyxl模块介绍 openpyxl模块是一个读写Excel 2010文档的Python库,如果要处理更早格式的Excel文档,需要用到额外的库,openpyxl是一个比较综合的工具,能够同时读 ...

  2. 详见github

    本栏博客不再专门更新,详见:https://github.com/dxscjx123/LeetCode

  3. Linux系统编程——进程间通信(一)

    基本操作命令: ps -ajx/-aux/-ef 查看进程间状态/的相互关系 top 动态显示系统中的进程 nice 按照指定的优先级运行 /renice 改变正在运行的进程的优先级 kill -9杀 ...

  4. AtomicReference 和 volatile 的区别

    顾名思义,就是不会被打断!!!!!! https://www.cnblogs.com/lpthread/p/3909231.html java.util.concurrent.atomic工具包,支持 ...

  5. Eclipse中部署ES源码运行

    https://stackoverflow.com/questions/40924671/how-to-build-elasticsearch-source-code-using-gradle Gra ...

  6. Django-form組件

    Django的Form主要具有一下几大功能: 生成HTML标签 验证用户数据(显示错误信息) HTML Form提交保留上次提交数据 初始化页面显示内容 一.创建Form类 1 2 3 4 5 6 7 ...

  7. AC日记——「HNOI2017」礼物 LiBreOJ 2020

    #2020. 「HNOI2017」礼物 思路: A题进程: 一眼出式子->各种超时过不去->看题解明白还有fft这个东西->百度文库学习fft->学习dft->学习fft ...

  8. SQL快速入门 ( MySQL快速入门, MySQL参考, MySQL快速回顾 )

    SQL 先说点废话,很久没发文了,整理了下自己当时入门 SQL 的笔记,无论用于入门,回顾,参考查询,应该都是有一定价值的,可以按照目录各取所需.SQL数据库有很多,MySQL是一种,本文基本都是SQ ...

  9. centos系统服务管理

    系统服务管理工具: chkconfig(所有linux发行版都有),用法很简单,如下: usage:   chkconfig --list [name]          chkconfig --ad ...

  10. php 正则验证字符串是否为数字

    PHP 正则验证字符串是否为数字 方法一: php中利用正则表达式验证字符串是否为数字一件非常容易的事情,最主要的是如何写好正则表达式以及掌握正则表达式的写法,在此利用正则表达式的方式来列举一下判断数 ...