Peekaboo(2019年上海网络赛K题+圆上整点)
题目链接
题意
你的位置在\(O(0,0)\),\(A\)的位置为\((x_1,y_1)\),\(B\)的位置为\((x_2,y_2)\),现在已知\(a=OA,b=OB,c=AB\),问你有多少对满足题意的\(A,B\)。
思路
由于\(a,b,c\)都是整数,\(O,A,B\)的坐标为整数,所以如果存在满足题意的点对,那么\(a,b\)一定是勾股数,且\(a^2=x_1^2+y_1^2,b=x_2^2+y_2^2\),所以我们可以通过求出所有的\((x_1,y_1),(x_2,y_2)\)然后看\(c\)是否等于\(AB\)。
对于\(a^2=x^2+y^2\),此时要推荐一个优秀的视频,根据这个视频里面说的即可解决这题。
如果没有时间看那么长的视频的可以看洛谷圆上整点的板题的题解里面的解释。
代码
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define fi first
#define se second
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://Code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)
const double eps = 1e-8;
const int mod = 1000000007;
const int maxn = 1000000 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
int t, cnt;
LL a, b, c;
pair<pii,pii> vec[maxn];
vector<pii> A, B;
bool check(LL x1, LL y1, LL x2, LL y2) {
return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) == c * c;
}
int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
void solve(LL x, LL d, vector<pii> &vec) {
if(x == 1 || x % 4 != 1) return;
for(int s = 1; 2LL * s * s <= x; ++s) {
LL tmp = x - 1LL * s * s;
int t = (int)sqrt(tmp);
if(1LL * t * t != tmp) ++t;
if(1LL * s * s + 1LL * t * t != x) continue;
if(gcd(s, t) != 1) continue;
if(s >= t) continue;
vec.emplace_back((1LL * t * t - 1LL * s * s) * d, 2 * d * s * t);
}
}
void GaussInteger(LL x, vector<pii> &vec) {
for(int i = 1; 1LL * i * i <= x; ++i) {
if(x % i) continue;
solve(x / i, i, vec);
if(1LL * i * i != x) solve(i, x / i, vec);
}
}
void fillpoint(LL x, vector<pii> &vec) {
int num = vec.size();
for(int i = 0; i < num; ++i) {
vec.emplace_back(vec[i].se, vec[i].fi);
}
for(int i = 0; i < 2 * num; ++i) {
vec.emplace_back(vec[i].fi, -vec[i].se);
vec.emplace_back(-vec[i].fi, vec[i].se);
vec.emplace_back(-vec[i].fi, -vec[i].se);
}
vec.emplace_back(x, 0);
vec.emplace_back(-x, 0);
vec.emplace_back(0, x);
vec.emplace_back(0, -x);
}
int main() {
#ifndef ONLINE_JUDGE
FIN;
time_t startclock = clock();
#endif // ONLINE_JUDGE
scanf("%d", &t);
while(t--) {
scanf("%lld%lld%lld", &a, &b, &c);
cnt = 0;
A.clear(), B.clear();
GaussInteger(a, A), GaussInteger(b, B);
fillpoint(a, A), fillpoint(b, B);
for(auto num1:A) {
for(auto num2:B) {
if(check(num1.fi, num1.se, num2.fi, num2.se)) {
vec[++cnt] = make_pair(num1, num2);
}
}
}
sort(vec + 1, vec + cnt + 1);
printf("%d\n", cnt);
for(int i = 1; i <= cnt; ++i) {
printf("%d %d %d %d\n", vec[i].fi.fi, vec[i].fi.se, vec[i].se.fi, vec[i].se.se);
}
}
#ifndef ONLINE_JUDGE
time_t endclock = clock();
printf("It costs %.3fs\n", 1.0 * (endclock - startclock) / CLOCKS_PER_SEC);
#endif // ONLINE_JUDGE
return 0;
}
Peekaboo(2019年上海网络赛K题+圆上整点)的更多相关文章
- 2019 ICPC上海网络赛 A 题 Lightning Routing I (动态维护树的直径)
题目: 给定一棵树, 带边权. 现在有2种操作: 1.修改第i条边的权值. 2.询问u到其他一个任意点的最大距离是多少. 题解: 树的直径可以通过两次 dfs() 的方法求得.换句话说,到任意点最远的 ...
- Magic Master(2019年南昌网络赛E题+约瑟夫环)
目录 题目链接 题意 思路 代码 题目链接 传送门 题意 初始时你有\(n\)张牌(按顺序摆放),每一次操作你将顶端的牌拿出,然后按顺序将上面的\(m\)张牌放到底部. 思路 首先我们发下拿走\(1\ ...
- 2019年南京网络赛E题K Sum(莫比乌斯反演+杜教筛+欧拉降幂)
目录 题目链接 思路 代码 题目链接 传送门 思路 首先我们将原式化简: \[ \begin{aligned} &\sum\limits_{l_1=1}^{n}\sum\limits_{l_2 ...
- 2019上海网络赛B题(差分 + 离散化 or 差分 + 思维)
这题.....队里都没怎么训练差分,导致败北...写了一堆线段树嘤嘤嘤,到最后也是超时,比赛结束后看到了差分的思想于是就去学了一手. 其实了解差分思想的一眼就能看出来是差分了.但是如果对n差分的话很明 ...
- [2019上海网络赛F题]Rhyme scheme
题目链接 题意,求出合法的长度为n的字典序第k小字符串,合法的定义为除了最后一位,每一位的取值范围为'A'到'A'+pos-1,而最后一位的取值范围'A'到当前字符串最大值+1. 队友tql,Orz ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 K题 center
You are given a point set with nn points on the 2D-plane, your task is to find the smallest number o ...
- [2019上海网络赛J题]Stone game
题目链接 CSLnb! 题意是求出给定集合中有多少个合法子集,合法子集的定义为,子集和>=总和-子集和$\& \&$子集和-(子集的子集和)<=总和-子集和. 其实就是很简 ...
- 2019 ACM-ICPC 上海网络赛 B. Light bulbs (差分)
题目链接:Light bulbs 比赛链接:The Preliminary Contest for ICPC Asia Shanghai 2019 题意 给定 \(N\) 个灯泡 (编号从 \(0\) ...
- 2019 ICPC南昌网络赛 B题
英雄灭火问题忽略了一点丫 一个超级源点的事情,需要考虑周全丫 2 #include<cstdio> #include<cstring> #include<queue> ...
随机推荐
- 总线宽度VS总线带宽
很多人把计算机总线宽度和总线带宽混为一谈,其实他们是不一样的. 总线宽度:总线宽度一般指CPU中运算器与存储器之间进行互连的内部总线二进制位数,影响吞吐量,即下面说的总线位宽. 总线带宽:总线的带宽指 ...
- python3 获取当前日期的时间戳,以及n天后的日期时间戳
#coding=utf- import time import datetime t=datetime.datetime.now() #当前日期 t1 =t.strftime('%Y-%m-%d 00 ...
- 解密httpclient,dbcp,jedis,c3p0,druid,okhttp都在使用的连接池技术
最近在连接池上面栽了个跟头(参见这里),引起我对池技术的强烈关注,这几天总结了一下很多场景都会使用的池技术: 池概念 pool,中文翻译为水池,但是在英文中,还有一种解释是 an organizati ...
- Spring Boot + Vue 前后端分离开发,权限管理的一点思路
在传统的前后端不分的开发中,权限管理主要通过过滤器或者拦截器来进行(权限管理框架本身也是通过过滤器来实现功能),如果用户不具备某一个角色或者某一个权限,则无法访问某一个页面. 但是在前后端分离中,页面 ...
- Docker核心组件的关系
- 缓存雪崩、穿透如何解决,如何确保Redis只缓存热点数据?
缓存雪崩如何解决? 缓存穿透如何解决? 如何确保Redis缓存的都是热点数据? 如何更新缓存数据? 如何处理请求倾斜? 实际业务场景下,如何选择缓存数据结构 缓存雪崩 缓存雪崩简单说就是所有请求都从缓 ...
- Scala 系列(五)—— 集合类型综述
一.集合简介 Scala中拥有多种集合类型,主要分为可变的和不可变的集合两大类: 可变集合: 可以被修改.即可以更改,添加,删除集合中的元素: 不可变集合类:不能被修改.对集合执行更改,添加或删除操作 ...
- oracle 更新日期字段
update field set BEGINDATE=to_date('2017-02-03 10:30:20','yyyy-mm-dd hh24:mi:ss')
- redis的主从复制,哨兵值守
环境: 主服务器:192.168.10.10 Centos 7 redis-5.0.4 从服务器:192.168.10.129 Centos 7 redis-5.0.4 从服务器:192. ...
- 【开发笔记】- Idea启动Gradle报错:Warning:Unable to make the module: reading, related gradle configuration was not found. Please, re-import the Gradle project and try again
报错信息: Warning:Unable to make the module: reading, related gradle configuration was not found. Please ...