vijos p1233
来源:互联网 发布:上海万户网络怎么样 编辑:程序博客网 时间:2024/05/22 13:40
多边形面积,注意退化成一条线的情况。
#include <iostream>#include <algorithm>#include <cmath>#include <cstdio>using namespace std;const double EPS = 1e-9;const double INF = 1e30;const double PI = 3.1415926;struct pt{double x,y;pt(double x=0,double y=0):x(x),y(y){}pt read(){int a,b;scanf("%d%d",&a,&b);this->x=a;this->y=b;return *this;}};typedef pt vec;inline vec operator - (vec a,vec b){return vec(a.x-b.x,a.y-b.y);}inline double dot(vec a,vec b){return a.x*b.x+a.y*b.y;}inline double len(vec a){return sqrt(dot(a,a));}inline double cross(vec a,vec b){return a.x*b.y-a.y*b.x;}inline bool operator < (const vec &a,const vec &b){return a.x<b.x || (a.x==b.x && a.y<b.y);}inline int dcmp(double x){if(fabs(x)<EPS)return 0;return (x>0)?1:-1;}double PolygonAera(pt *p,int n){double aera=0.0;for(int i=1;i<n-1;i++)aera+=cross(p[i]-p[0],p[i+1]-p[0]);return aera/2.0;}double pc(pt *p,int n){double c=len(p[0]-p[n-1]);for(int i=1;i<n;i++)c+=len(p[i]-p[i-1]);return c;}int chull(pt *p,int n,pt *ch){sort(p,p+n);int m=0;for(int i=0;i<n;i++){while(m>1 && cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)m--;ch[m++]=p[i];}int k=m;for(int i=n-2;i>=0;i--){while(m>k && cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)m--;ch[m++]=p[i];}if(n>1)m--;return m;}int main(){int n;scanf("%d",&n);pt s[20],ch[20];for(int i=0;i<n;i++)s[i].read();int m=chull(s,n,ch);bool ok=false;for(int i=0;i<m;i++)if(i>1 && dcmp(cross(ch[i]-ch[i-1],ch[i-1]-ch[i-2]))!=0)ok=true;double c=pc(ch,m);double d=PolygonAera(ch,m);if(ok)printf("%.2lf\n%.2lf\n",c,d);else printf("%.2lf\n%.2lf\n",c/2.0,0.0);return 0;}
0 0
- vijos p1233
- vijos p1233
- Tyvj P1233 数列
- 洛谷 P1233 木棍加工
- 洛谷 P1233 木棍加工
- HDOJ P1233 还是畅通工程
- vijos 1070
- vijos 1020
- VIJOS 1180
- VIJOS-P1130
- vijos-1788
- vijos-1385
- VIJOS-P1312
- Vijos 1059
- Vijos 1061
- vijos P1071
- VIJOS-P1033
- vijos 中青局
- Redis——简单介绍
- 【Redis】二 JAVA redis 3.0.7连接
- 海量数据处理常用思路和方法
- 12-PHP的FastCGI
- =>goes to
- vijos p1233
- 13-如何执行PHP脚本
- TimesTen可以缓存哪些版本的Oracle数据库
- AppSync for iOS7安装教程、Cydia软件源安装AppSync补丁
- 14-PHP脚本的执行细节
- CacheJob
- React-基于React & Reflux 的评论框组件 (ES6)
- 15-操作码OpCode
- uva 10664 Luggage