POJ 3348 Cows
来源:互联网 发布:前端性能优化的方式 编辑:程序博客网 时间:2024/05/16 10:16
POJ 3348 Cows
求出凸包的面积除以50就是ans。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<vector>using namespace std;#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)#define DOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)#define oo 1e6#define eps 1e-8#define nMax 100010#define pb push_back#define F first#define S second#define bug puts("OOOOh.....");#define zero(x) (((x)>0?(x):-(x))<eps)int dcmp(double x){ if(fabs(x)<eps) return 0; return x>0?1:-1;}class point {public: double x,y; point (double x=0,double y=0):x(x),y(y) {} void make(double _x,double _y) {x=_x;y=_y;} void read() { scanf("%lf%lf",&x,&y); } void out() { printf("%.2lf %.2lf\n",x,y);} double len() { return sqrt(x*x+y*y); } point friend operator - (point const& u,point const& v) { return point(u.x-v.x,u.y-v.y); } point friend operator + (point const& u,point const& v) { return point(u.x+v.x,u.y+v.y); } double friend operator * (point const& u,point const& v) { return u.x*v.y-u.y*v.x; } double friend operator ^ (point const& u,point const& v) { return u.x*v.x+u.y*v.y; } point friend operator * (point const& u,double const& k) { return point(u.x*k,u.y*k); }friend bool operator < (point const& u,point const& v){if(dcmp(v.x-u.x)==0) return dcmp(u.y-v.y)<0;return dcmp(u.x-v.x)<0;}friend bool operator != (point const& u,point const& v){return dcmp(u.x-v.x) || dcmp(u.y-v.y);}};typedef class line{public: point a,b; line() {} line (point a,point b):a(a),b(b){} void make(point u,point v) {a=u;b=v;} void read() { a.read(),b.read(); }}segment;int ConvexHull(point *p,int n,point *ret){sort(p,p+n);int m=0;for(int i=0;i<n;i++){while(m>1 && dcmp((ret[m-1]-ret[m-2])*(p[i]-ret[m-1]))<=0) m--;ret[m++]=p[i];}int k=m;for(int i=n-2;i>=0;i--) {while(m>k && dcmp((ret[m-1]-ret[m-2])*(p[i]-ret[m-1]))<=0) m--;ret[m++]=p[i];}if(n>1) m--;return m;}double Area(point *p,int n){//bugdouble ret=0.0;for(int i=1;i<n-1;i++){//printf("---i=%d\n",i);//printf("---%.2lf\n",(p[i]-p[0])*(p[i+1]-p[i]);ret += (p[i]-p[0])*(p[i+1]-p[i])*0.5;}//printf("%.2lf\n",ret);return fabs(ret);}point p[nMax],q[nMax];int n;int main(){#ifndef ONLINE_JUDGEfreopen("input.txt","r",stdin);#endifwhile(~scanf("%d",&n)){FOR(i,0,n-1) p[i].read();int m=ConvexHull(p,n,q);double area = Area(q,m);printf("%d\n",(int)area/50);}return 0;}
- poj 3348 Cows
- POJ 3348 Cows
- poj 3348 Cows
- poj 3348 Cows
- POJ 3348 Cows
- poj 3348 Cows
- POJ 3348 Cows
- POJ 3348 Cows
- POJ 3348 Cows
- poj 3348 Cows
- POJ 3348 Cows
- POJ-3348:Cows
- poj 3348 Cows(求凸包面积)
- POJ 3348 Cows(凸包)
- POJ 3348 Cows(凸包求面积)
- POJ 3348 Cows 求凸包面积
- POJ 3348 || Cows(求凸包面积
- POJ 3348 Cows (凸包)
- Github、NodeJS使用心得
- POJ 1003
- 短训学习录(八)——快结业了
- linux下jdk安装及VMware Tools安装内核版本缺失问题
- POJ 1004
- POJ 3348 Cows
- Google Spanner原理- 全球级的分布式数据库
- linux程序调试
- 笔试智力题(收集中)【for_wind】
- 无标题窗口拖动
- zip文件解压
- java 实现 连连看的算法
- Hadoop伪分布式环境搭建(能力工场--小马哥整理)
- 考研复习计划(8.20-8.31)