Cod sursa(job #3304507)

Utilizator Cyb3rBoltSbora Ioan-David Cyb3rBolt Data 24 iulie 2025 13:11:46
Problema Pachete Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.92 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("pachete.in");
ofstream fout("pachete.out");
#define int long long
int n;

struct Iris {
    int x, y;

    void read() { fin >> x >> y; }
    Iris() { x = y = 0; }
    Iris(int a, int b) { x = a, y = b; }
    bool operator == (const Iris &p) const { return p.x == x && p.y == y; }
    bool operator < (const Iris &p) const { return x < p.x || (x == p.x && y < p.y); }
    bool operator > (const Iris &p) const { return x > p.x || (x == p.x && y > p.y); }
}start;
vector<Iris> v1, v2, v3, v4;

struct IrisHasher {
    size_t operator()(const Iris &p) const {
        return hash<int>()(p.x) ^ (hash<int>()(p.y) << 1);
    }
};
unordered_map<Iris, int, IrisHasher> mapa;

inline int gcd(int a, int b) {
    while(b) {
        int rest = a % b;
        a = b, b = rest;
    }
    return a;
}

inline Iris getPanta(Iris a, Iris b) {
    int x = a.x - b.x;
    int y = a.y - b.y;
    int semn = 0; ///0 = + ; 1 = -
    if(x < 0) semn ^= 1, x = -x;
    if(y < 0) semn ^= 1, y = -y;
    int div = gcd(x, y);
    Iris rez;
    rez.x = x / div;
    rez.y = y / div;
    if(semn == 1) rez.x *= (-1);
    return rez;
}

signed main()
{
    fin >> n;
    start.read();
    for(int i=1; i<=n; i++) {
        Iris p; p.read();
        if(p.x >= start.x && p.y >= start.y) v1.push_back(p);
        else if(p.x >= start.x && p.y <= start.y) v2.push_back(p);
        else if(p.x <= start.x && p.y <= start.y) v3.push_back(p);
        else v4.push_back(p);
    }
    int rez = 0;
    for(Iris i : v1) mapa[getPanta(start, i)]++;
    rez += mapa.size(), mapa.clear();
    for(Iris i : v2) mapa[getPanta(start, i)]++;
    rez += mapa.size(), mapa.clear();
    for(Iris i : v3) mapa[getPanta(start, i)]++;
    rez += mapa.size(), mapa.clear();
    for(Iris i : v4) mapa[getPanta(start, i)]++;
    rez += mapa.size();
    fout << rez;

    return 0;
}