Untitled

 avatar
user_7227489
plain_text
17 days ago
6.2 kB
5
Indexable
Never
A:
#include <bits/stdc++.h>
using namespace std;

struct Point {
    long long x, y;
};

int checkOrientation(Point a, Point b, Point c) {
    long long res = (b.y - a.y) * (c.x - b.x) - (b.x - a.x) * (c.y - b.y);
    return (res == 0) ? 0 : (res > 0) ? 1 : 2;
}

bool onSegment(Point a, Point b, Point c) {
    return b.x <= max(a.x, c.x) && b.x >= min(a.x, c.x) &&
           b.y <= max(a.y, c.y) && b.y >= min(a.y, c.y);
}

bool checkIntersection(Point p1, Point q1, Point p2, Point q2) {
    int o1 = checkOrientation(p1, q1, p2);
    int o2 = checkOrientation(p1, q1, q2);
    int o3 = checkOrientation(p2, q2, p1);
    int o4 = checkOrientation(p2, q2, q1);

    if (o1 != o2 && o3 != o4)
        return true;

    if (o1 == 0 && onSegment(p1, p2, q1)) return true;
    if (o2 == 0 && onSegment(p1, q2, q1)) return true;
    if (o3 == 0 && onSegment(p2, p1, q2)) return true;
    if (o4 == 0 && onSegment(p2, q1, q2)) return true;

    return false;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        Point p1, q1, p2, q2;
        cin >> p1.x >> p1.y >> q1.x >> q1.y >> p2.x >> p2.y >> q2.x >> q2.y;
        cout << (checkIntersection(p1, q1, p2, q2) ? "YES" : "NO") << endl;
    }
    return 0;
}

B:

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

static bool solve(int a,int b,int c){
    //breaking a
    if(b==c && a%2==0)
        return true;
    if(a-b==c || a-c == b)
        return true;
    return false;
}
int main() {
    int tests;
    cin >> tests;
    for (int i = 0; i < tests; ++i) {
        int a,b,c;
        cin >>a >> b >>c;
        if(solve(a,b,c) || solve(b,a,c) || solve(c,a,b))
            cout << "YES\n";
        else
            cout << "NO\n";
    }
    return 0;
}


C:

#include <bits/stdc++.h>

using namespace std;

long long calc(pair<long long, long long> point1, pair<long long, long long> point2) {
    return (point2.first - point1.first) * (point2.first - point1.first) + 
           (point2.second - point1.second) * (point2.second - point1.second);
}
int main(){
    long long n;
    long long minDis = LLONG_MAX;
    cin>>n;
    
    vector<pair<long long,long long>> points(n);
    for(long long i=0;i<n;i++){
        cin>>points[i].first >> points[i].second;
    }
    
    sort(points.begin(),points.end());
    set<pair<long long,long long>> apoints {{points[0].second,points[0].first}};
    
    long long j=0;
    
    for(long long i=1;i<n;i++){
        long long td = ceil(sqrt(minDis));
        
        while(j<i && points[j].first < points[i].first -td){
            apoints.erase({points[j].second,points[j].first});
            j++;
        }
        
        auto lowerB = apoints.lower_bound({points[i].second-td,0});
        auto upperB = apoints.upper_bound({points[i].second+td,0});
        
        for(auto it=lowerB;it!=upperB;it++){
            minDis = min(minDis,calc({it->second,it->first},points[i]));
        }
        
        apoints.insert({points[i].second,points[i].first});
    }
    
    cout<< minDis <<endl;
    return 0;
}

D:
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

long long calculateDistanceSquared(int x1, int y1, int x2, int y2) {
    return 1LL * (x2 - x1) * (x2 - x1) + 1LL * (y2 - y1) * (y2 - y1);
}

int main() {
    int tests;
    cin >> tests;
    for (int i = 0; i < tests; ++i) {
        int circles, xs, ys, xTar, yTar, temp1, temp2, flag = 0;
        cin >> circles;
        vector<int> x(circles);
        vector<int> y(circles);

        for (int j = 0; j < circles; ++j) {
            cin >> temp1 >> temp2;
            x[j] = temp1;
            y[j] = temp2;
        }
        cin >> xs >> ys >> xTar >> yTar;

        long long myDisSquared = calculateDistanceSquared(xs, ys, xTar, yTar);
        for (int j = 0; j < circles; ++j) {
            long long thisDisSquared = calculateDistanceSquared(x[j], y[j], xTar, yTar);
            if (thisDisSquared <= myDisSquared) {
                flag = 1;
                break;
            }
        }

        if (flag == 1)
            cout << "NO\n";
        else
            cout << "YES\n";
    }
    return 0;
}


E:

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

long long calculateDistanceSquared(int x1, int y1, int x2, int y2) {
    return 1LL * (x2 - x1) * (x2 - x1) + 1LL * (y2 - y1) * (y2 - y1);
}

int main() {
    int tests;
    cin >> tests;
    for (int i = 0; i < tests; ++i) {
        int circles, xs, ys, xTar, yTar, temp1, temp2, flag = 0;
        cin >> circles;
        vector<int> x(circles);
        vector<int> y(circles);

        for (int j = 0; j < circles; ++j) {
            cin >> temp1 >> temp2;
            x[j] = temp1;
            y[j] = temp2;
        }
        cin >> xs >> ys >> xTar >> yTar;

        long long myDisSquared = calculateDistanceSquared(xs, ys, xTar, yTar);
        for (int j = 0; j < circles; ++j) {
            long long thisDisSquared = calculateDistanceSquared(x[j], y[j], xTar, yTar);
            if (thisDisSquared <= myDisSquared) {
                flag = 1;
                break;
            }
        }

        if (flag == 1)
            cout << "NO\n";
        else
            cout << "YES\n";
    }
    return 0;
}


F:

#include <bits/stdc++.h>

using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        long long n, m;
        cin >> n >> m;
        long long x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        
        int ans;
        
        if ((x1 == 1 || x1 == n) && (y1 == 1 || y1 == m) ||
            (x2 == 1 || x2 == n) && (y2 == 1 || y2 == m)) {
            ans = 2;
        } else if (x1 == 1 || x1 == n || y1 == 1 || y1 == m ||
                 x2 == 1 || x2 == n || y2 == 1 || y2 == m) {
            ans = 3;
        } else {
            ans = 4;
        }
        
        cout << ans << endl;
    }
    return 0;
}

I:

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int len,i;
    cin >> len;
    for (int j = 0; j < len; ++j) {
        cin >> i;
        if(360%(180-i) == 0 && i >= 60 && i!=180)
            cout << "YES\n";
        else
            cout << "NO\n";
    }

    return 0;
}
Leave a Comment