UVA 11800 - Determine the Shape
来源:互联网 发布:移动公司网络监控软件 编辑:程序博客网 时间:2024/05/16 17:59
判断四边形形状的。题目中只要求输入整型数据,所以定义结构体的时候用INT没用double
代码如下:
#include<iostream>using namespace std;struct Point{int x,y;Point(int x=0,int y=0):x(x),y(y){}};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);}bool operator == (const Vector& a,const Vector& b){return a.x==b.x&&a.y==b.y;}bool parallel(Vector a,Vector b){return a.x*b.y==a.y*b.x;}int Length2(Vector a){return a.x*a.x+a.y*a.y;}bool vertical(Vector a,Vector b){if((a.x*b.x+a.y*b.y)==0)return true;else return false;}int main(){freopen("data.txt","r",stdin);int T;cin>>T;int kase=0;while(T--){cout<<"Case "<<++kase<<": ";Point a[5];for(int i=0;i<4;++i){cin>>a[i].x>>a[i].y;}bool can=0;for(int i=1;i<4;++i){Point t=a[0];Point q=a[i];Point r;Point s;if(i==1){r=a[2];s=a[3];}else if(i==2){r=a[1];s=a[3];}else if(i==3){r=a[1];s=a[2];}if(parallel(t-q,r-s)){//cout<<i<<" zz "<<t.x<<' '<<t.y<<' '<<q.x<<' '<<q.y<<' '<<r.x<<' '<<r.y<<' '<<s.x<<' '<<s.y<<endl;can=1;if(parallel(s-q,r-t))can=1;else if(parallel(r-q,s-t)){Point tmp=r;r=s;s=tmp;can=1;}else {cout<<"Trapezium"<<endl;break;}if(vertical(t-q,s-q)&&(Length2(t-q)==Length2(s-q))){cout<<"Square"<<endl;break;}else if(vertical(t-q,s-q)){cout<<"Rectangle"<<endl;break;}else if(Length2(t-q)==Length2(s-q)){cout<<"Rhombus"<<endl;break;}else {cout<<"Parallelogram"<<endl;break;}}}if(!can)cout<<"Ordinary Quadrilateral"<<endl;}return 0;}
0 0
- UVa 11800 - Determine the Shape
- uva 11800 - Determine the Shape
- UVA 11800 Determine the Shape
- UVa 11800 Determine the Shape
- UVA 11800 - Determine the Shape
- uva 11800 - Determine the Shape
- UVA 11800 Determine the Shape
- UVa 11800 - Determine the Shape
- UVA 11800 Determine the Shape
- UVA 11800 - Determine the Shape 几何
- UVa 11800 Determine the Shape(几何)
- [UVA]11800-Determine the Shape(计算几何)
- UVA 11800 - Determine the Shape(计算几何)
- 几何 入门题 UVA 11800 - Determine the Shape
- UVA 11800 —— Determine the Shape(几何基础)
- UVA 11800 Determine the Shape(判四边形)
- Determine the Shape - UVa 11800 凸包判断四边形
- uva 11800 Determine the Shape 判断四边形形状(计算几何)
- hdu1385
- Linux内核代码笔记5----I/O体系结构和设备驱动模型
- 简单的WebUtil函数
- 英国调查报告称中国梦吸引力首超美国梦
- HTTP正则表达式
- UVA 11800 - Determine the Shape
- Let me go home :)
- C++虚函数小结
- Notifications(通知)
- 【转】ARM编程:Scatter文件的编写、分析
- Python更新notepad.cc文件脚本
- poj2406
- Java NIO系列教程(六) Selector
- 4.19日记