UVA UKE
查看原帖
UVA UKE
637788
kimi0705楼主2024/8/1 09:29

UVA RMJ 炸了,UVA 也炸了

#include <bits/stdc++.h>
using namespace std;
int t, n;
char c;
double x, y;
struct point {
    double x, y;
};
vector<point> Points;
double crossProduct(point A, point B) { return A.x * B.y - A.y * B.x; }
double distance(point A, point B) { return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y)); }
bool compare(point A, point B, point o) {
    A.x -= o.x, A.y -= o.y, B.x -= o.x, B.y -= o.y;
    double tmp = crossProduct(A, B);
    if (tmp > 0)
        return true;
    else
        return false;
}
bool cmp(point a, point b) { return a.x == b.x ? a.y < b.y : a.x < b.x; }
bool cmp2(point a, point b) { return compare(a, b, Points[0]); }
int main() {
    cin >> t;
    while (t--) {
        cin >> n;
        for (int i = 1; i <= n; i++) {

            cin >> x >> y >> c;
            if (c == 'Y') Points.push_back({ x, y });
        }
        cout << Points.size() << '\n';
        sort(Points.begin(), Points.end(), cmp);
        sort(Points.begin() + 1, Points.end(), cmp2);
        for (point p : Points) printf("%.0f %.0f\n", p.x, p.y);
    }
    return 0;
}

2024/8/1 09:29
加载中...