Geometric Shapes - POJ 3449
2015-08-20 11:51
316 查看
Geometric Shapes
Description
While creating a customer logo, ACM uses graphical utilities to draw a picture that can later be cut into special fluorescent materials. To ensure proper processing, the shapes in the picture cannot intersect. However, some logos contain such intersecting
shapes. It is necessary to detect them and decide how to change the picture.
Given a set of geometric shapes, you are to determine all of their intersections. Only outlines are considered, if a shape is completely inside another one, it is not counted as an intersection.
Input
Input contains several pictures. Each picture describes at most 26 shapes, each specified on a separate line. The line begins with an uppercase letter that uniquely identifies the shape inside the corresponding picture. Then there is a kind of the shape
and two or more points, everything separated by at least one space. Possible shape kinds are:
• square: Followed by two distinct points giving the opposite corners of the square.
• rectangle: Three points are given, there will always be a right angle between the lines connecting the first point with the second and the second with the third.
• line: Specifies a line segment, two distinct end points are given.
• triangle: Three points are given, they are guaranteed not to be co-linear.
• polygon: Followed by an integer number N (3 ≤ N ≤ 20) and N points specifying vertices of the polygon in either clockwise or anti-clockwise order. The polygon will never intersect itself and its sides will have non-zero length.
All points are always given as two integer coordinates X and Y separated with a comma and enclosed in parentheses. You may assume that |X|, |Y | ≤ 10000.
The picture description is terminated by a line containing a single dash (“-”). After the last picture, there is a line with one dot (“.”).
Output
For each picture, output one line for each of the shapes, sorted alphabetically by its identifier (X). The line must be one of the following:
• “X has no intersections”, if X does not intersect with any other shapes.
• “X intersects with A”, if X intersects with exactly 1 other shape.
• “X intersects with A and B”, if X intersects with exactly 2 other shapes.
• “X intersects with A, B, . . ., and Z”, if X intersects with more than 2 other shapes.
Please note that there is an additional comma for more than two intersections. A, B, etc. are all intersecting shapes, sorted alphabetically.
Print one empty line after each picture, including the last one.
Sample Input
Sample Output
题意:给你一些图形,让你判断哪些图形有交点。
思路:没啥思路,可以算是一个模拟题了。写的时候细心些,应该不难过。
AC代码如下:
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 1537 | Accepted: 647 |
While creating a customer logo, ACM uses graphical utilities to draw a picture that can later be cut into special fluorescent materials. To ensure proper processing, the shapes in the picture cannot intersect. However, some logos contain such intersecting
shapes. It is necessary to detect them and decide how to change the picture.
Given a set of geometric shapes, you are to determine all of their intersections. Only outlines are considered, if a shape is completely inside another one, it is not counted as an intersection.
Input
Input contains several pictures. Each picture describes at most 26 shapes, each specified on a separate line. The line begins with an uppercase letter that uniquely identifies the shape inside the corresponding picture. Then there is a kind of the shape
and two or more points, everything separated by at least one space. Possible shape kinds are:
• square: Followed by two distinct points giving the opposite corners of the square.
• rectangle: Three points are given, there will always be a right angle between the lines connecting the first point with the second and the second with the third.
• line: Specifies a line segment, two distinct end points are given.
• triangle: Three points are given, they are guaranteed not to be co-linear.
• polygon: Followed by an integer number N (3 ≤ N ≤ 20) and N points specifying vertices of the polygon in either clockwise or anti-clockwise order. The polygon will never intersect itself and its sides will have non-zero length.
All points are always given as two integer coordinates X and Y separated with a comma and enclosed in parentheses. You may assume that |X|, |Y | ≤ 10000.
The picture description is terminated by a line containing a single dash (“-”). After the last picture, there is a line with one dot (“.”).
Output
For each picture, output one line for each of the shapes, sorted alphabetically by its identifier (X). The line must be one of the following:
• “X has no intersections”, if X does not intersect with any other shapes.
• “X intersects with A”, if X intersects with exactly 1 other shape.
• “X intersects with A and B”, if X intersects with exactly 2 other shapes.
• “X intersects with A, B, . . ., and Z”, if X intersects with more than 2 other shapes.
Please note that there is an additional comma for more than two intersections. A, B, etc. are all intersecting shapes, sorted alphabetically.
Print one empty line after each picture, including the last one.
Sample Input
A square (1,2) (3,2) F line (1,3) (4,4) W triangle (3,5) (5,5) (4,3) X triangle (7,2) (7,4) (5,3) S polygon 6 (9,3) (10,3) (10,4) (8,4) (8,1) (10,2) B rectangle (3,3) (7,5) (8,3) - B square (1,1) (2,2) A square (3,3) (4,4) - .
Sample Output
A has no intersections B intersects with S, W, and X F intersects with W S intersects with B W intersects with B and F X intersects with B A has no intersections B has no intersections
题意:给你一些图形,让你判断哪些图形有交点。
思路:没啥思路,可以算是一个模拟题了。写的时候细心些,应该不难过。
AC代码如下:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #include<iostream> #include<vector> #include<string> using namespace std; typedef long long ll; struct Point { double x,y; Point(double x=0,double y=0):x(x),y(y){} }; struct node { string str; int num; Point p[30]; }arr[30]; bool cmp(node a,node b) { return a.str<b.str; } double PI=acos(-1.0),eps=1e-8; typedef Point Vector; Vector operator + (Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);} Vector operator - (Vector A,Vector B){return Vector(A.x-B.x,A.y-B.y);} Vector operator * (Vector A,double p){return Vector(A.x*p,A.y*p);} Vector operator / (Vector A,double p){return Vector(A.x/p,A.y/p);} int dcmp(double x){return (x>eps)-(x<-eps);} double Cross(Vector A,Vector B){return A.x*B.y-A.y*B.x;} double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;} double Length(Vector A){return sqrt(Dot(A,A));} double Angle(Vector A,Vector B){return acos(Dot(A,B)/Length(A)/Length(B));} Vector Rotate(Vector A,double rad){return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)-A.y*cos(rad));} int T,t,n,m; vector<string> vc[30]; char s[20]; bool SegmentIntersection(Point a1,Point a2,Point b1,Point b2) { double c1=Cross(a2-a1,b1-a1); double c2=Cross(a2-a1,b2-a1); double c3=Cross(b2-b1,a1-b1); double c4=Cross(b2-b1,a2-b1); return dcmp(c1)*dcmp(c2)<=0 && dcmp(c3)*dcmp(c4)<=0 &&dcmp(min(a1.x,a2.x)-max(b1.x,b2.x))<=0 &&dcmp(min(a1.y,a2.y)-max(b1.y,b2.y))<=0 &&dcmp(min(b1.x,b2.x)-max(a1.x,a2.x))<=0 &&dcmp(min(b1.y,b2.y)-max(a1.y,a2.y))<=0; } bool solve(int a,int b) { int i,j,k; for(i=0;i<arr[a].num;i++) for(j=0;j<arr[b].num;j++) if(SegmentIntersection(arr[a].p[i],arr[a].p[i+1],arr[b].p[j],arr[b].p[j+1])>0) return 1; return 0; } void read(Point &a) { scanf("%s",s); sscanf(s,"(%lf,%lf)",&a.x,&a.y); } int main() { int i,j,k; double a1,a2,b1,b2; Point a,b,c,d; string str; while(true) { n=0; while(true) { n++; scanf("%s",s); if(s[0]=='.' || s[0]=='-') { n--; break; } arr .str=s; scanf("%s",s); if(s[0]=='s') { read(a);read(b); arr .num=4; arr .p[1]=a; arr .p[3]=b; c=Rotate((a-b)/2,PI/2); arr .p[2]=(a+b)/2+c; arr .p[0]=arr .p[4]=(a+b)/2-c; } else if(s[0]=='r') { read(a);read(b);read(c); arr .num=4; if(dcmp(Dot(a-c,b-c))==0) swap(b,c); arr .p[1]=a; arr .p[2]=b; arr .p[3]=c; arr .p[0]=arr .p[4]=a-b+c; } else if(s[0]=='l') { read(arr .p[0]);read(arr .p[1]); arr .num=1; } else if(s[0]=='t') { read(a);read(b);read(c); arr .num=3; arr .p[1]=a; arr .p[2]=b; arr .p[0]=arr .p[3]=c; } else if(s[0]=='p') { scanf("%d",&arr .num); for(i=1;i<=arr .num;i++) read(arr .p[i]); arr .p[0]=arr .p[arr .num]; } } if(n==0) break; sort(arr+1,arr+1+n,cmp); for(i=1;i<=n;i++) vc[i].clear(); for(i=1;i<=n;i++) for(j=i+1;j<=n;j++) if(solve(i,j)) { vc[i].push_back(arr[j].str); vc[j].push_back(arr[i].str); } for(i=1;i<=n;i++) { m=vc[i].size(); cout<<arr[i].str; if(m==0) cout<<" has no intersections"<<endl; else if(m==1) cout<<" intersects with "<<vc[i][0]<<endl; else if(m==2) cout<<" intersects with "<<vc[i][0]<<" and "<<vc[i][1]<<endl; else { cout<<" intersects with "; for(j=0;j<m-1;j++) cout<<vc[i][j]<<", "; cout<<"and "<<vc[i][m-1]<<endl; } } printf("\n"); } }
相关文章推荐
- 【拾遗】C++ STL容器begin(),end()
- jQuery里$(this)和this的区别在哪?
- BZOJ2658: [Zjoi2012]小蓝的好友(mrx)
- 张国祥老师在绍兴培训M购门店员工
- js实现文字在按钮上滚动的方法
- CentOS下安装SVN
- size_t 类型
- POJ 3259 Wormholes 判断负环
- Android 自定义ContentProvider
- js坑爹笔试题目汇总(持续更新中)
- 编程题二
- UE4 CPU Profiling
- IC,你应该知道的半导体科普知识
- API访问custom-actions.xml和custom-actionmodel.xml的方法
- 使用axis公布weblogic(一个)
- Json.Net学习笔记
- Spring的注解配置与XML配置之间的比较
- js 判断手机横竖屏
- jquery实现漫天雪花飞舞的圣诞祝福雪花效果代码分享
- python的OS内置函数