社区讨论

90pts 求助

P1355神秘大三角参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@m2coohc2
此快照首次捕获于
2024/10/17 10:30
去年
此快照最后确认于
2025/11/04 17:01
4 个月前
查看原帖
wa10,实在不知错在哪里
第十个test将三角内判成了三角外
CPP
// P1355
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;

struct Point{
    int x, y;

    Point operator-(const Point a){
        Point res;
        res.x = x-a.x;
        res.y = y-a.y;
        return res;
    }
};

int det(Point a, Point b){
    return (a.x*b.y)-(a.y*a.x);
}

int dot(Point a, Point b){
    return (a.x*b.x)+(a.y*b.y);
}

bool same(Point a, Point b){
    return (a.x == b.x && a.y == b.y);
}

bool on_seg(Point a, Point p, Point q){
    return ((det(a-q, p-q)) == 0 && dot(p-a, q-a) <= 0);
}

bool in_polygon(Point now, Point p[3]){
    int cnt = 0;
    Point a, b;
    int x, y, z;
    for (int i=0; i<3; i++){
        a = p[i];
        b = p[(i+1)%3];
        x = det(now-a, b-a);
        y = a.y-now.y;
        z = b.y-now.y;
        if (x > 0 && y <= 0 && z > 0)
            cnt += 1;
        if (x < 0 && z <= 0 && y > 0)
            cnt -= 1;
    }
    return (cnt != 0);
}

void sol(Point p[3], Point a){
    for (int i=0; i<3; i++){
        if (same(p[i], a)){
            cout << 4;
            return;
        }
    }
    if (on_seg(a, p[0], p[1]) || on_seg(a, p[0], p[2]) || on_seg(a, p[1], p[2])){
        cout << 3;
        return;
    }
    if (in_polygon(a, p)){
        cout << 1;
        return;
    }
    cout << 2;
    return;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    Point p[3];
    char _;
    for (int i=0; i<3; i++){
        cin >> _ >> p[i].x >> _ >> p[i].y >> _;
        // scanf("(%lf,%lf)", &p[i].x, &p[i].y);
    }
    Point a;
    cin >> _ >> a.x >> _ >> a.y >> _;
    sol(p, a);
    return 0;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...