弱校联萌十一大决战之背水一战K. King's Sanctuary
2015-10-07 20:41
417 查看
The king found his adherents were building four sanctuaries for him. He is interested about the positions of the sanctuaries and wants to know whether they would form a parallelogram, rectangle, diamond, square
or anything else.
The first line of the input is T(1 <= T <= 1000), which stands for the number of test cases you need to solve.
Each case contains four lines, and there are two integers in each line, which shows the position of the four sanctuaries. And it is guaranteed that the positions are given clockwise. And it is always a convex polygon, if you connect the four points clockwise.
For every test case, you should output "Case #t: " first, where t indicates the case number and counts from 1, then output the type of the quadrilateral.
5
0 0
1 1
2 1
1 0
0 0
0 1
2 1
2 0
0 0
2 1
4 0
2 -1
0 0
0 1
1 1
1 0
0 0
1 1
2 1
3 0
Case #1: Parallelogram
Case #2: Rectangle
Case #3: Diamond
Case #4: Square
Case #5: Others
这个题不是自己写的 基础集合 判断四个点构成什么图形 据队友说 要考虑斜率为0和无穷大的情况
or anything else.
Input
The first line of the input is T(1 <= T <= 1000), which stands for the number of test cases you need to solve.Each case contains four lines, and there are two integers in each line, which shows the position of the four sanctuaries. And it is guaranteed that the positions are given clockwise. And it is always a convex polygon, if you connect the four points clockwise.
Output
For every test case, you should output "Case #t: " first, where t indicates the case number and counts from 1, then output the type of the quadrilateral.
Sample Input
50 0
1 1
2 1
1 0
0 0
0 1
2 1
2 0
0 0
2 1
4 0
2 -1
0 0
0 1
1 1
1 0
0 0
1 1
2 1
3 0
Sample Output
Case #1: ParallelogramCase #2: Rectangle
Case #3: Diamond
Case #4: Square
Case #5: Others
这个题不是自己写的 基础集合 判断四个点构成什么图形 据队友说 要考虑斜率为0和无穷大的情况
#include <iostream> #include <cstdio> using namespace std; struct point{ int x,y; }p[4]; int chang(point a,point b){ return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); } int kab,kbc,kcd,kda,ablen,bclen,cdlen,dalen; bool jud1(){ return (p[1].y-p[0].y)*(p[2].x-p[3].x)==(p[2].y-p[3].y)*(p[1].x-p[0].x); } bool jud2(){ return (p[3].y-p[0].y)*(p[2].x-p[1].x)==(p[2].y-p[1].y)*(p[3].x-p[0].x); } bool jud3(){ if(p[1].x==p[0].x&&p[3].y==p[0].y) return 1; if(p[1].y==p[0].y&&p[3].x==p[0].x) return 1; return ((p[1].y-p[0].y)*(p[3].y-p[0].y)+(p[1].x-p[0].x)*(p[3].x-p[0].x))==0; } bool jud4(){ return ablen==bclen&&bclen==cdlen&&cdlen==dalen; } int main() { int t,ca=1; cin>>t; while(t--){ for(int i=0;i<4;i++){ scanf("%d%d",&p[i].x,&p[i].y); } //kab=xie(p[0],p[1]),kbc=xie(p[1],p[2]),kcd=xie(p[2],p[3]),kda=xie(p[3],p[0]); ablen=chang(p[0],p[1]),bclen=chang(p[1],p[2]); cdlen=chang(p[2],p[3]),dalen=chang(p[3],p[0]); printf("Case #%d: ",ca++); if(jud1()&&jud2()&&jud3()&&jud4()){ puts("Square"); } else if(jud4()){ puts("Diamond"); } else if(jud1()&&jud2()&&jud3()){ puts("Rectangle"); } else if(jud1()&&jud2()){ puts("Parallelogram"); } else puts("Others"); } return 0; }
相关文章推荐
- 关于fragment响应回退键的处理与fragment的删除
- Opencv 读取摄像头和视频数据
- iOS-UITouch,UIEvent使用介绍
- Android模拟器访问本地Web应用
- 设计模式大全
- 软工视频8-12章
- 动态规划算法入门
- SpriteBuilder使用Shader Effect的另一种方法
- C语言的存储类型的个人理解
- SpriteBuilder使用Shader Effect的另一种方法
- SpriteBuilder使用Shader Effect的另一种方法
- NOIP2010 关押罪犯
- Linux下高并发socket最大连接数所受的限制问题
- CPU流水线的探秘之旅
- 弱校联萌十一大决战之背水一战C. Counting Pair
- IOS 传感器
- Code optimization and organization in Javascript / jQuery
- Cubietruck查看CPU及硬盘温度
- 【转】Ubuntu通过修改配置文件进行网络配置
- NOIP2010 乌龟棋