题目大意就是给出一笔画的顺序,问一笔画将平面分成了几部分
……暴力乱搞就可以啦。。。。
#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;
}