题目概述

原题参考F-S=1
给出坐标(A,B),问是否存在坐标(X,Y),使得这两个点和原点围起来的三角形的面积是1,如果存在,输出一组解,否则输出-1

思路分析

结论+板子,没什么好分析的,想到了就好写,利用向量的叉乘求解三角形的面积,因为给出的点中有一个原点,向量就很好表示,之后就是求解BX-AY=2的一组解,利用扩欧求解即可
当gcd(a,b)大于2,也就是不能被2整除时,该方程无整数解,否则存在整数解

参考代码

#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define pll pair<long long, long long>
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<long long>
#define ll long long
#define ull unsigned long long
const ll INF = 9187201950435737471;
const int inf = 2139062143;
const ll mod = 1e9 + 7;
const double eps = 1e-6;
const double PI = acos(-1.0);
ll a, b, x, y;
ll exgcd(ll a, ll b, ll &x, ll &y) {
    if(!b) {
        x = 1, y = 0;
        return a;
    }
    int d = exgcd(b, a%b, y, x);
    y -= (a/b) * x;
    return d;
}
void solve() {
    cin >> a >> b;
    ll d = gcd(a, b);
    if(d > 2) cout << -1 << endl;
    else {
        exgcd(b, -a, x, y);
        x *= 2/d, y *= 2/d;
        cout << x << " " << y << endl;
    }
}
int main() {
#ifdef xrl
    freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout);
#endif
    FAST_IO;
    int t = 1;
    //cin >> t;
    while(t --) solve();
#ifdef xrl
    cout << "Time used = " << (double)(clock() * 1.0 / CLOCKS_PER_SEC) << "s";
#endif
    return 0;
}

做题反思

反思自己为什么没想起来这个公式,以及为什么前面做得慢导致这里没多少时间hhhhh

posted on 2024-02-13 20:07  山余木  阅读(65)  评论(0)    收藏  举报