[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 ...
随机推荐
- HTML跳转新窗口的方法
笔试遇到这样的一个问题,特意整理一下. 方法一 纯HTML <a href="http://www.cnblogs.com" target="_blank" ...
- javascript继承机制 & call apply使用说明
一.继承机制 1.对象冒充:构造函数使用 this 关键字给所有属性和方法赋值,可使 ClassA 构造函数成为 ClassB 的方法,然后调用它. function ClassZ() { this. ...
- hdu 2717 Catch That Cow(广搜bfs)
题目链接:http://i.cnblogs.com/EditPosts.aspx?opt=1 Catch That Cow Time Limit: 5000/2000 MS (Java/Others) ...
- Jmeter===Jmeter中使用CSV Data Set Config参数化不重复数据执行N遍(转)
Jmeter中使用CSV Data Set Config参数化不重复数据执行N遍 要求: 今天要测试上千条数据,且每条数据要求执行多次,(模拟多用户多次抽奖) 1.用户id有175个,且没有任何排序规 ...
- AMD嵌入式G系列SoC协助优化Gizmo 2开发板
http://www.gizmosphere.org/ AMD嵌入式G系列SoC协助优化Gizmo 2开发板 http://news.zol.com.cn/491/4910444.html
- Kotlin 学习使用之旅(二)
为什么从二开始呢?再此之前已经有了一篇了,那是刚知道kotlin的时候草(chao)来(chao)的并且学习一篇, 这次是自己在项目中正式使用并且遇到的一些问题记录,供kotlin新入门的童鞋参考,避 ...
- sicily 1052. Candy Sharing Game
Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description A number of students sit in a circle ...
- C 实现有追求的线程池 探究
引言 线程池很普通的老话题,讨论的很多.深入的不多,也就那些基础库中才能见到这种精妙完备的技巧.而本文随大流 想深入简述一种高效控制性强的一种线程池实现. 先引入一个概念, 惊群. 简单举个例子. 春 ...
- https配置注意细节
直接将阿里云https的ca配置配置好之后如果不通的话很有可能是防火墙原因造成的,还有就是nginx要用1.10以上版本的
- C语言写随机数
#include <stdio.h> #include <stdlib.h> #include <time.h> ; unsigned int rand0(); v ...