Peekaboo (2019 K Cup title in Shanghai in the network + the whole point of the circle)

Topic Link

Portal

The meaning of problems

Your location \ (O (0,0) \) , \ (A \) position as \ ((x_1, Y_1) \) , \ (B \) location \ ((x_2, y_2) \ ) , now known \ (a = OA, OB = b, c = AB \) , ask how much you have to meet the meaning of the title \ (a, B \) .

Thinking

Since (a, b, c \) \ are integers, \ (O, A, B \) coordinates of an integer, if that satisfies the meaning of the title point, then the \ (a, b \) must Pythagorean number, and \ (a = x_1 ^ 2 ^ 2 + 2 ^ Y_1, B = x_2 ^ 2 + 2 ^ Y_2 \) , we can obtain all \ ((x_1, y_1), (x_2, y_2) \) and then look at \ (c \) is equal to \ (AB \) .

For \ (A ^ 2 = 2 + the y-the X-^ ^ 2 \) , this time to recommend a good video , according to this video which says you can solve this problem.

If you do not have time to read so long video can be seen on the valley of Los rounded point of the solution to a problem the question of the plate inside explanation.

Code

#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;
}

Guess you like

Origin www.cnblogs.com/Dillonh/p/11535199.html