[AGC025D]Choosing Points
[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的更多相关文章
- 「AGC025D」 Choosing Points
「AGC025D」 Choosing Points 神仙构造题. 首先你会尝试暴力做,先随便选一个点,然后把当前能选得全选上,然后你发现这样样例都过不了. 然后我们可以这样考虑:你把距离为 \(\sq ...
- 2018.07.12 atcoder Choosing Points(数学分析好题)
传送门 一句话题意:给出n,d1,d2" role="presentation" style="position: relative;">n,d ...
- AtCoder Grand Contest 025 Problem D - Choosing Points
题目大意:输入$n,d1,d2$,你要找到$n^2$个整点 x, y 满足$0 \leqslant x, y<2n$.并且找到的任意两个点距离,既不是$\sqrt{d1}$,也不是 $\sqrt ...
- atcoder题目合集(持续更新中)
Choosing Points 数学 Integers on a Tree 构造 Leftmost Ball 计数dp+组合数学 Painting Graphs with AtCoDeer tarja ...
- 【AtCoder】AGC025题解
A - Digits Sum 枚举即可 代码 #include <bits/stdc++.h> #define fi first #define se second #define pii ...
- AGC025简要题解
AGC025简要题解 B RGB Coloring 一道简单题,枚举即可. C Interval Game 考虑可以进行的操作只有两种,即左拉和右拉,连续进行两次相同的操作是没有用的. 左拉时肯定会选 ...
- 有理数的稠密性(The rational points are dense on the number axis.)
每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.
- [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. ...
- CF219D. Choosing Capital for Treeland [树形DP]
D. Choosing Capital for Treeland time limit per test 3 seconds memory limit per test 256 megabytes i ...
随机推荐
- 获取应用版本号,版本名称,包名,AppName,图标,是否是系统应用,获取手机中所有应用,所有进程
PackageManager packageManager = getPackageManager(); PackageInfo packageInfo; = packageManager.getPa ...
- 【Python学习】Jupyter解决单个变量输出问题
使用Jupyter的时候有时候发现,我明明写了好几个变量打印,但是它只显示最后一个.Out只有一个. 但是使用下面的语句.就可以实现多个输出. from IPython.core.interactiv ...
- Django 国内最全教程
https://code.ziqiangxuetang.com/django/django-tutorial.html
- TensorFlow计算模型—计算图
TensorFlow是一个通过计算图的形式来表述计算的编程系统.其中的Tnesor,代表它的数据结构,而Flow代表它的计算模型.TensorFlow中的每一个计算都是计算图上的一个节点,而节点之间的 ...
- PIL处理图片信息
最近遇到了图片处理的一些问题,python提供了一些库可以很方便地帮助我们解决这些问题,在这里把我这几天的学习总结一下. 一.提取图片的RGB值 1.非代码:如果只是为了提取某张图片或者某个像素点的R ...
- linux命令(12):ping命令
1.ping网关:ping –b 192.168.1.1 2.ping指定次数:ping -c 10 192.168.1.100 3.时间间隔和次数限制的ping:ping -c 10 -i 0.5 ...
- NativeScriptEngineService 被调用流程
AbsractSearchScritp 有个lookup! NativeScriptEngineService search()会调用 script.setLookup() NativeScriptE ...
- nginx+uwsgi+django+virtualenv+supervisor部署web服务器
wsgi 全称web server gateway interface,wsgi不是服务器,也不是python模块,只是一种协议,描述web server如何和web application通信的规则 ...
- redis 安装及安装遇到的问题解决
https://blog.csdn.net/jy0902/article/details/19248299 http://q.fireflyclub.org/?/article/24 https:// ...
- 2017-2018 ACM-ICPC Northern Eurasia (Northeastern European Regional) Contest (NEERC 17) 日常训练
A - Archery Tournament 题目大意:按时间顺序出现靶子和射击一个位置,靶子的圆心为(x, y)半径为r,即圆与x轴相切,靶子不会重叠,靶子被击中后消失, 每次射击找出哪个靶子被射中 ...