gggyt  
没谁离不开谁

  题意:判断是否存在内核。

  半平面交存板子。

/*  gyt
       Live up to every day            */
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<cstring>`
#include<queue>
#include<set>
#include<string>
#include<map>
#include <time.h>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 1e4+100;
const ll maxm = 1e7;
const ll mod = 1e9 + 7;
const int INF = 0x3f3f3f;
const int inf =0x3f3f3f;
const db eps = 1e-9;
const int kind=26;
struct point  {
    double x,y;
    point(double x=0,double y=0): x(x),y(y){}
}an[maxn], bn[maxn], cn[maxn];
typedef point Vector;
Vector operator +(point a,point b)  {
    return Vector(a.x+b.x,a.y+b.y);
}
Vector operator *(point a,double b)  {
    return Vector(a.x*b,a.y*b);
}
Vector operator -(point a,point b)  {
    return Vector(a.x-b.x,a.y-b.y);
}
double dot(Vector a,Vector b)  {    //内积
    return a.x*b.x+a.y*b.y;
}
double cross(Vector a,Vector b)  {     //外积
    return a.x*b.y-a.y*b.x;
}
int n, m;
db A, B, C;
//获取Ax+By+c=0
void getline(point a, point b) {
    A=b.y-a.y;
    B=a.x-b.x;
    C=b.x*a.y-a.x*b.y;
}
//getline()得到的直线与点a,b构成直线的交点
point intersect(point a, point b) {
    db u=fabs(A*a.x+B*a.y+C);
    db v=fabs(A*b.x+B*b.y+C);
    point ans;
    ans.x=(a.x*v+b.x*u)/(u+v);
    ans.y=(a.y*v+b.y*u)/(u+v);
    return ans;
}
void cut() {
    int cnt=0;
    for (int i=1; i<=m; i++) {
        if (A*cn[i].x+B*cn[i].y+C>=0)  bn[++cnt]=cn[i];
        else {
            if (A*cn[i-1].x+B*cn[i-1].y+C>0) {
                bn[++cnt]=intersect(cn[i-1], cn[i]);
            }
            if (A*cn[i+1].x+B*cn[i+1].y+C>0) {
                bn[++cnt]=intersect(cn[i+1], cn[i]);
            }
        }
    }
    for (int i=1; i<=cnt; i++) {
        cn[i]=bn[i];
    }
    cn[0]=bn[cnt];
    cn[cnt+1]=bn[1];
    m=cnt;
}
void deal() {
    for (int i=1; i<=n; i++) {
        cn[i]=an[i];
    }
    an[n+1]=an[1];
    cn[n+1]=an[1];
    cn[0]=an[n];
    m=n;
    for (int i=1; i<=n; i++) {
        getline(an[i], an[i+1]);
        cut();
    }
}
void solve() {
    while(scanf("%d", &n)!=EOF && n) {
        for (int i=1; i<=n; i++) {
            scanf("%lf%lf", &an[i].x, &an[i].y);
        }
        reverse(an+1, an+1+n);
        deal();
        if (m)  puts("1");
        else  puts("0");
    }
}
int main() {
    int t = 1;
    //freopen("in.txt", "r", stdin);
   // scanf("%d", &t);
    while(t--)
        solve();
    return 0;
}

 

posted on 2017-10-20 16:31  gggyt  阅读(185)  评论(0编辑  收藏  举报