UVA1342That Nice Euler Circuit

万恶的几何……

题目大意就是给出一笔画的顺序,问一笔画将平面分成了几部分

……暴力乱搞就可以啦。。。。

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
const double eps = 1e-8;
int dblcmp(double x){
    if (fabs(x) < eps) return 0;
    return x > 0 ? 1 : -1;
}
const double pi = acos(-1.0);
inline double sqr(double x){return x * x;}
struct Point2D{
    double x, y;
    Point2D(){}
    Point2D(double a, double b) : x(a), y(b){}
    void input(){scanf("%lf%lf", &x, &y);}
    void output(){printf("%.2lf %.2lf", x, y);}
    Point2D operator + (const Point2D &a)const{return Point2D(x + a.x, y + a.y);}
    Point2D operator - (const Point2D &a)const{return Point2D(x - a.x, y - a.y);}
    Point2D operator * (const double &a)const{return Point2D(x * a, y * a);}
    Point2D operator / (const double &a)const{return Point2D(x / a, y / a);}
    bool operator == (const Point2D &a)const{return dblcmp(x - a.x) == 0 && dblcmp(y - a.y) == 0;}
    bool operator < (const Point2D &a)const{
        return dblcmp(x - a.x) < 0 || (dblcmp(x - a.x) == 0 || dblcmp(y - a.y) < 0);
    }
    double len(){return sqrt(sqr(x) + sqr(y));}
};
double det(const Point2D &a, const Point2D &b){return a.x * b.y - a.y * b.x;}
double dot(const Point2D &a, const Point2D &b){return a.x * b.x + a.y * b.y;}
double dist(const Point2D &a, const Point2D &b){return (a - b).len();}
double angle(Point2D a, Point2D b){return acos(dot(a, b) / a.len() / b.len());}
double dist_point_seg(Point2D p, Point2D s, Point2D t){
    if (dot(p - s, t - s) < 0) return dist(p, s);
    if (dot(p - t, s - t) < 0) return dist(p, t);
    return fabs(det(p - s, p - t) / dist(s, t));
}
Point2D rotate(const Point2D &p, double a){
    double tx = p.x, ty = p.y;
    return Point2D(tx * cos(a) - ty * sin(a), tx * sin(a) + ty * cos(a));
}
Point2D getinter(Point2D p, Point2D v, Point2D q, Point2D w){
    Point2D u = p - q;
    double t = det(w, u) / det(v, w);
    return p + v * t;
}
typedef Point2D Vector2D;
bool judgeInter(Point2D a1, Point2D a2, Point2D b1, Point2D b2){
    double d1, d2, d3, d4;
    d1 = det(a2 - a1, b1 - a1);
    d2 = det(a2 - a1, b2 - a1);
    d3 = det(b2 - b1, a1 - b1);
    d4 = det(b2 - b1, a2 - b1);
    return dblcmp(d1 * d2) < 0 && dblcmp(d3 * d4) < 0;
}
bool OnSeg(const Point2D &p, const Point2D &a1, const Point2D &a2){
    return dblcmp(det(a1 - p, a2 - p)) == 0 && dblcmp(dot(a1 - p, a2 - p)) < 0;
}
const int maxn = 300 + 10;
Point2D p[maxn], v[maxn * maxn];
int main(){
    //freopen("in", "r", stdin);
    int n, kase = 0;
    while(scanf("%d", &n) == 1 && n){
        for (int i = 0; i < n; i++){
            p[i].input(); v[i] = p[i];
        }
        n -= 1;
        int c = n, e = n;
        for (int i = 0; i < n; i++)
            for (int j = i + 1; j < n; j++)
                if (judgeInter(p[i], p[i + 1], p[j], p[j + 1]))
                    v[c++] = getinter(p[i], p[i + 1] - p[i], p[j], p[j + 1] - p[j]);
        sort(v, v + c);
        c = unique(v, v + c) - v;
        for (int i = 0; i < c; i++)
            for (int j = 0; j < n; j++)
                if (OnSeg(v[i], p[j], p[j + 1])) e++;
        printf("Case %d: There are %d pieces.\n", ++kase, e + 2 - c);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值