麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

Hdu 1558 Segment set(并查集+幾何)

2019-11-14 11:53:29
字體:
來源:轉載
供稿:網友
題目地址:http://acm.hdu.edu.cn/showPRoblem.php?pid=1558

思路:判斷線段相交(注意端點相交),若相交并入同一集合。

#include<cstdio>#include<queue>#include<cmath>#include<cstring>#include<iostream>#include<algorithm>#define debuusing namespace std;const double eps=1e-10;const int maxn=1e3+50;const int INF=0x3f3f3f3f;struct Point{    double x,y;    Point(double x=0,double y=0):x(x),y(y) {}};struct Line{    Point x,y;    Line(Point x=NULL,Point y=NULL):x(x),y(y) {}};typedef Point Vector;Vector Operator - (const Point &A,const Point &B){    return Vector(A.x-B.x,A.y-B.y);}int n,tot;Line L[maxn];int fa[maxn],w[maxn];int dcmp(double x){    if(fabs(x)<eps) return 0;    else return x<0?-1:1;}bool operator == (const Point &a, const Point &b){    return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;}double Dot(const Vector &A,const Vector &B){    return A.x*B.x+A.y*B.y;}double Cross(const Vector &A,const Vector &B){    return A.x*B.y-A.y*B.x;}bool SegmentProperIntersection(const Point &a1, const Point &a2, const Point &b1, const Point &b2){    double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1), c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1);    return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0;}bool OnSegment(Point p,Point a1,Point a2){    return dcmp(Cross(a1-p,a2-p))==0&&dcmp(Dot(a1-p,a2-p))<0;}int Find(int x){    return fa[x]==x?x:fa[x]=Find(fa[x]);}void Union(int x,int y){    fa[x]=y;    w[y]+=w[x];}void init(){    tot=0;    for(int i=1; i<=n; i++)    {        w[i]=1;        fa[i]=i;    }}int check(Point p,Point x,Point y){    return p==x||p==y;}int main(){#ifdef debug    freopen("in.in","r",stdin);#endif // debug    int t,cas=0;    scanf("%d",&t);    while(t--)    {        cas++;        if(cas!=1) printf("/n");        scanf("%d",&n);        init();        for(int i=0; i<n; i++)        {            char ch;            getchar();            scanf("%c",&ch);            if(ch=='P')            {                tot++;                double x1,y1,x2,y2;                scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);                Point tmp1=Point(x1,y1),tmp2=Point(x2,y2);                L[tot]=Line(tmp1,tmp2);                for(int j=1; j<tot; j++)                {                    if(SegmentProperIntersection(L[tot].x,L[tot].y,L[j].x,L[j].y)||                            OnSegment(L[tot].x,L[j].x,L[j].y)||OnSegment(L[tot].y,L[j].x,L[j].y)||                            check(L[tot].x,L[j].x,L[j].y)||check(L[tot].y,L[j].x,L[j].y))                    {                        //cout<<tot<<" "<<j<<endl;                        int xx=Find(tot),yy=Find(j);                        if(xx!=yy)                        {                            Union(xx,yy);                        }                    }                }            }            else            {                int k;                scanf("%d",&k);                printf("%d/n",w[Find(k)]);            }        }    }    return 0;}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 欧美日韩大片在线观看 | 一级空姐毛片 | 成人在线视频精品 | 国产午夜精品一区二区三区免费 | 免费毛片播放 | 精品一二三区视频 | 黄色免费在线视频网站 | 久久久三区| 成人午夜视频在线观看免费 | 久久久久久久久久久亚洲 | 免费午夜视频在线观看 | 91九色网址| xvideos korean| 国产免费一级淫片 | 久久精品国产清自在天天线 | 成人在线观看地址 | 欧美综合成人 | 狠狠一区二区 | 久久福利电影网 | 51国产偷自视频区视频小蝌蚪 | 成人国产在线看 | 久久99深爱久久99精品 | 激情网站在线观看 | 污视频在线免费播放 | 牛牛碰在线 | 久久久免费电影 | 特级毛片a级毛片100免费 | 黄色高清免费网站 | 九九综合九九 | 91精品国产乱码久久久久久久久 | 久久久久九九九女人毛片 | 亚洲欧美日韩中文在线 | 久久成人福利 | 国产黄色免费网站 | 免费黄色欧美视频 | 亚洲日色 | 国产91精品久久久久久 | 视频一区二区三区在线播放 | 韩国19禁在线 | 超碰人人做人人爱 | 日本a大片 |