日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

POJ 1584 A Round Peg in a Ground Hole 判断凸多边形,点到线段距离,点在多边形内

發布時間:2024/10/8 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ 1584 A Round Peg in a Ground Hole 判断凸多边形,点到线段距离,点在多边形内 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

ACM博客_kuangbin

POJ 1584 A Round Peg in a Ground Hole(判斷凸多邊形,點到線段距離,點在多邊形內)

A Round Peg in a Ground Hole

Time Limit:?1000MS?Memory Limit:?10000K
Total Submissions:?4438?Accepted:?1362

Description

The DIY Furniture company specializes in assemble-it-yourself furniture kits. Typically, the pieces of wood are attached to one another using a wooden peg that fits into pre-cut holes in each piece to be attached. The pegs have a circular cross-section and so are intended to fit inside a round hole.?
A recent factory run of computer desks were flawed when an automatic grinding machine was mis-programmed. The result is an irregularly shaped hole in one piece that, instead of the expected circular shape, is actually an irregular polygon. You need to figure out whether the desks need to be scrapped or if they can be salvaged by filling a part of the hole with a mixture of wood shavings and glue.?
There are two concerns. First, if the hole contains any protrusions (i.e., if there exist any two interior points in the hole that, if connected by a line segment, that segment would cross one or more edges of the hole), then the filled-in-hole would not be structurally sound enough to support the peg under normal stress as the furniture is used. Second, assuming the hole is appropriately shaped, it must be big enough to allow insertion of the peg. Since the hole in this piece of wood must match up with a corresponding hole in other pieces, the precise location where the peg must fit is known.?
Write a program to accept descriptions of pegs and polygonal holes and determine if the hole is ill-formed and, if not, whether the peg will fit at the desired location. Each hole is described as a polygon with vertices (x1, y1), (x2, y2), . . . , (xn, yn). The edges of the polygon are (xi, yi) to (xi+1, yi+1) for i = 1 . . . n ? 1 and (xn, yn) to (x1, y1).

Input

Input consists of a series of piece descriptions. Each piece description consists of the following data:?
Line 1 < nVertices > < pegRadius > < pegX > < pegY >?
number of vertices in polygon, n (integer)?
radius of peg (real)?
X and Y position of peg (real)?
n Lines < vertexX > < vertexY >?
On a line for each vertex, listed in order, the X and Y position of vertex The end of input is indicated by a number of polygon vertices less than 3.

Output

For each piece description, print a single line containing the string:?
HOLE IS ILL-FORMED if the hole contains protrusions?
PEG WILL FIT if the hole contains no protrusions and the peg fits in the hole at the indicated position?
PEG WILL NOT FIT if the hole contains no protrusions but the peg will not fit in the hole at the indicated position

Sample Input

5 1.5 1.5 2.0 1.0 1.0 2.0 2.0 1.75 2.0 1.0 3.0 0.0 2.0 5 1.5 1.5 2.0 1.0 1.0 2.0 2.0 1.75 2.5 1.0 3.0 0.0 2.0 1

Sample Output

HOLE IS ILL-FORMED PEG WILL NOT FIT

Source

Mid-Atlantic 2003

題意:

給出N個點,一個圓的半徑和圓心坐標:

  • 如果N個點構成的多邊形不是凸多邊形,輸出:HOLE IS ILL-FORMED
  • 如果N個點構成凸多邊形,圓在凸多邊形內,輸出:PEG WILL FIT
  • 如果N個點構成凸多邊形,圓不在凸多邊內,輸出:PEG WILL NOT FIT
  • 分析:

    首先是判斷給出了多邊形是不是凸多邊形。然后判斷圓包含在凸多邊形中。

    一定要保證圓心在凸多邊形里面,然后判斷圓心到每條線段的距離要大于等于半徑。

    #include <stdio.h> #include <math.h> #include <algorithm> #include <string.h> #include <math.h> using namespace std;const double eps = 1e-8; int sgn(double x) {if(fabs(x) < eps)return 0;if(x < 0)return -1;else return 1; } struct Point {double x,y;Point(){}Point(double _x,double _y){x = _x;y = _y;}Point operator -(const Point &b)const{return Point(x - b.x,y - b.y);}//叉積double operator ^(const Point &b)const{return x*b.y - y*b.x;}//點積double operator *(const Point &b)const{return x*b.x + y*b.y;}void input(){scanf("%lf%lf",&x,&y);} }; struct Line {Point s,e;Line(){}Line(Point _s,Point _e){s = _s;e = _e;}//兩直線相交求交點//第一個值為0表示直線重合,為1表示平行,為0表示相交,為2是相交//只有第一個值為2時,交點才有意義pair<int,Point> operator &(const Line &b)const{Point res = s;if(sgn((s-e)^(b.s-b.e)) == 0){if(sgn((s-b.e)^(b.s-b.e)) == 0)return make_pair(0,res);//重合else return make_pair(1,res);//平行}double t = ((s-b.s)^(b.s-b.e))/((s-e)^(b.s-b.e));res.x += (e.x-s.x)*t;res.y += (e.y-s.y)*t;return make_pair(2,res);} };//*判斷線段相交 bool inter(Line l1,Line l2) {returnmax(l1.s.x,l1.e.x) >= min(l2.s.x,l2.e.x) &&max(l2.s.x,l2.e.x) >= min(l1.s.x,l1.e.x) &&max(l1.s.y,l1.e.y) >= min(l2.s.y,l2.e.y) &&max(l2.s.y,l2.e.y) >= min(l1.s.y,l1.e.y) &&sgn((l2.s-l1.e)^(l1.s-l1.e))*sgn((l2.e-l1.e)^(l1.s-l1.e)) <= 0 &&sgn((l1.s-l2.e)^(l2.s-l2.e))*sgn((l1.e-l2.e)^(l2.s-l2.e)) <= 0; }//兩點距離 double dist(Point a,Point b) {return sqrt((a-b)*(a-b)); }//判斷凸多邊形,允許共線邊 //點的編號0~n-1,可以是順時針和逆時針 bool isConvex(Point poly[],int n){bool s[3];memset(s,false,sizeof s);for(int i=0;i<n;i++){s[sgn( (poly[(i+1)%n]-poly[i])^(poly[(i+2)%n]-poly[i]) )+1]=true;if(s[0]&&s[2]) return false;}return true; }//點到線段的距離,返回點到線段最近的點 Point NearestPointToLineSeg(Point p,Line L) {Point result;double t=((p-L.s)*(L.e-L.s))/((L.e-L.s)*(L.e-L.s));if(t>=0&&t<=1){result.x=L.s.x+(L.e.x-L.s.x)*t;result.y=L.s.y+(L.e.y-L.s.y)*t;}else{if(dist(p,L.s)<dist(p,L.e))result=L.s;elseresult=L.e;}return result; }//判斷點在線段上 bool OnSeg(Point P,Line L) {returnsgn((L.s-P)^(L.e-P)) == 0 &&sgn((P.x - L.s.x) * (P.x - L.e.x)) <= 0 &&sgn((P.y - L.s.y) * (P.y - L.e.y)) <= 0; }//*判斷點在凸多邊形內 //點形成一個凸包,而且按逆時針排序(如果是順時針把里面的<0改為>0) //點的編號:0~n-1 //返回值: //-1:點在凸多邊形外 //0:點在凸多邊形邊界上 //1:點在凸多邊形內 int inConvexPoly(Point a,Point p[],int n) {for(int i = 0;i < n;i++){if(sgn((p[i]-a)^(p[(i+1)%n]-a)) < 0)return -1;else if(OnSeg(a,Line(p[i],p[(i+1)%n])))return 0;}return 1; }//*判斷點在任意多邊形內 //射線法,poly[]的頂點數要大于等于3,點的編號0~n-1 //返回值 //-1:點在凸多邊形外 //0:點在凸多邊形邊界上 //1:點在凸多邊形內 int inPoly(Point p,Point poly[],int n) {int cnt;Line ray,side;cnt = 0;ray.s = p;ray.e.y = p.y;ray.e.x = -100000000000.0;//-INF,注意取值防止越界for(int i = 0;i < n;i++){side.s = poly[i];side.e = poly[(i+1)%n];if(OnSeg(p,side))return 0;//如果平行軸則不考慮if(sgn(side.s.y - side.e.y) == 0)continue;if(OnSeg(side.s,ray)){if(sgn(side.s.y - side.e.y) > 0)cnt++;}else if(OnSeg(side.e,ray)){if(sgn(side.e.y - side.s.y) > 0)cnt++;}else if(inter(ray,side))cnt++;}if(cnt % 2 == 1)return 1;else return -1; }int n; Point o;//圓心 double R;//半徑 Point p[110]; int main() {while(scanf("%d",&n)!=EOF){if(n<3) break;scanf("%lf%lf%lf",&R,&o.x,&o.y);for(int i=0;i<n;i++)p[i].input();if(!isConvex(p,n)){//不是凸多邊形printf("HOLE IS ILL-FORMED\n");continue;}//圓心不在凸多邊形內if(inPoly(o,p,n)<0){printf("PEG WILL NOT FIT\n");continue;}bool flag=false;for(int i=0;i<n;i++){if(sgn(dist(o,NearestPointToLineSeg(o,Line(p[i],p[(i+1)%n]))) -R ) <0 ){flag=true;break;}}if(flag) printf("PEG WILL NOT FIT\n");else printf("PEG WILL FIT\n");}return 0; }

    ?

    總結

    以上是生活随笔為你收集整理的POJ 1584 A Round Peg in a Ground Hole 判断凸多边形,点到线段距离,点在多边形内的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 波多野结衣三区 | 91精品国产综合久久香蕉 | 国产素人在线观看 | 欧美交受高潮1 | 精品国产一区二区三区久久久久久 | 天天欧美| 久av在线| 亚洲性大片 | 人妻体内射精一区二区 | aaaa黄色| 欧美aa级 | 欧美精品 在线观看 | 国产精品视频在线播放 | 美女天天干 | 欧美性久久久久 | 高跟91娇喘 | 久久久精品人妻一区二区三区四 | 激情五月亚洲 | 中日韩在线观看 | 女儿的朋友5中汉字晋通话 欧美成人免费高清视频 | 人人射影院| 天天躁日日躁bbbbb | 午夜宅男影院 | 999精彩视频 | 9久精品 | 性猛交富婆╳xxx乱大交麻豆 | 成人精品视频一区二区三区尤物 | 激情丁香 | 中文字幕亚洲综合 | h视频在线看 | 黄污视频在线播放 | 91av综合| 色婷婷av一区二区三区gif | 在线观看岛国av | jizz在线免费观看 | 日本一区二区三区免费在线观看 | 依人在线| 波多野结衣潜藏淫欲 | 国产亚洲精品久久久久久777 | 国产精品久久久久一区二区 | 一级片免费看视频 | 色婷婷久久久亚洲一区二区三区 | 自偷自拍av| 国产精品成人无码免费 | 91系列在线观看 | 四虎福利视频 | 久久这里只有精品23 | 亚洲国产美女视频 | 国产中文字幕在线播放 | 男生操女生免费网站 | 中文字幕制服诱惑 | 在线精品一区二区 | 青娱乐极品在线 | 中国浓毛少妇毛茸茸 | 久草视频免费看 | 一区二区三区四区五区六区 | 国产热 | 国产女人高潮的av毛片 | 台湾黄色网址 | 国产乱子一区二区 | 久久婷五月 | 韩国欧美三级 | 欧美r级在线 | 在线观看成人av | 岛国av免费 | 亚洲一区二区三区视频在线 | 国产视频综合在线 | 美女色综合| 3d动漫精品啪啪一区二区竹菊 | 各种含道具高h调教1v1男男 | 久久99国产精品久久99 | av在线网址大全 | www.亚洲色图| 就要日就要操 | 91精品网 | 亚洲av熟女国产一区二区性色 | 性网| 成人免费在线小视频 | 少妇高潮视频 | 先锋影音av资源在线观看 | 欧美一级大片在线观看 | 国产精品超碰 | 亚洲の无码国产の无码步美 | 国产亚洲欧美日韩精品一区二区三区 | 日韩性xxx| 国产综合视频在线 | 91极品国产| 国产女人18水真多毛片18精品 | 免费福利小视频 | 夜色视频网站 | 黑人巨大精品 | 97超碰总站| 国产美女菊爆在线播放APP | 五月婷婷丁香 | 欧美亚洲综合在线 | 男人爽女人下面动态图 | 韩国成人免费视频 | 在线观看网址你懂的 | 欧美瑟瑟|