●POJ 3348 Cows

题链:

http://poj.org/problem?id=3348

题解:

计算几何,凸包,多边形面积

好吧,就是个裸题,没什么可讲的。

代码:

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 10050
using namespace std;
const double eps=1e-8;
int sign(double x){
	if(fabs(x)<=eps) return 0;
	return x<0?-1:1;
}
struct Point{
	double x,y;
	Point(double _x=0,double _y=0):x(_x),y(_y){}
	void Read(){scanf("%lf%lf",&x,&y);}
};
typedef Point Vector;
bool operator < (Point A,Point B){return sign(A.x-B.x)<0||(sign(A.x-B.x)==0&&sign(A.y-B.y)<0);}
bool operator == (Point A,Point B){return sign(A.x-B.x)==0&&sign(A.y-B.y)==0;}
Vector operator + (Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);}
Vector operator - (Point A,Point B){return Vector(A.x-B.x,A.y-B.y);}
double operator ^ (Vector A,Vector B){return A.x*B.y-A.y*B.x;}
Point D[MAXN],H[MAXN];
int Andrew(int dnt){
	int hnt=0,k=0;
	sort(D+1,D+dnt+1);
	dnt=unique(D+1,D+dnt+1)-D-1;
	for(int i=1;i<=dnt;i++){
		while(hnt>1&&sign((H[hnt]-H[hnt-1])^(D[i]-H[hnt-1]))<=0) hnt--;
		H[++hnt]=D[i];
	} k=hnt;
	for(int i=dnt-1;i>=1;i--){
		while(hnt>k&&sign((H[hnt]-H[hnt-1])^(D[i]-H[hnt-1]))<=0) hnt--;
		H[++hnt]=D[i];
	}
	return hnt;
}
double GCPA(int hnt){//Get_Convex_Polygon_Area
	double S=0;
	for(int i=1;i<hnt;i++) S+=(H[i]^H[i+1])/2;
	return S;
}
int main(){
	int N; scanf("%d",&N);
	for(int i=1;i<=N;i++) D[i].Read();
	printf("%d",(int)(GCPA(Andrew(N))/50));
	return 0;
}

  

原文地址:https://www.cnblogs.com/zj75211/p/8227651.html

时间: 2024-10-19 06:01:39

●POJ 3348 Cows的相关文章

POJ 3348 Cows 凸包 求面积

LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileName: POJ 3348 凸包面积 叉积.cpp * @Platform: Windows * @Author : Lweleth ([email protected]) * @Link : https://github.com/ * @Version : $Id$ */ #include <std

POJ 3348 Cows [凸包 面积]

Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9022   Accepted: 3992 Description Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are f

POJ 3348 Cows(凸包面积)

Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7515   Accepted: 3418 Description Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are f

poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207

Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7038   Accepted: 3242 Description Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are f

简单几何(凸包+多边形面积) POJ 3348 Cows

题目传送门 题意:求凸包 + (int)求面积 / 50 /************************************************ * Author :Running_Time * Created Time :2015/11/4 星期三 11:13:29 * File Name :POJ_3348.cpp ************************************************/ #include <cstdio> #include <a

poj 3348 Cows 求凸包面积

题目链接 大意: 求凸包的面积. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map> #include <set> #include <string> #include <queue>

POJ 3348 Cows(凸包+多边形面积)

先求出凸包,然后利用凸包求出面积,除以50就是答案 代码: #include<cstdio> #include<cmath> #include<algorithm> using namespace std; const int MAXN=10005; struct Point { double x, y; Point() {} Point(double x, double y) { this->x = x; this->y = y; } void read(

POJ 3348 Cows

简单的求凸多边形面积 求不规则多边形也是类似 只要选择的点是沿着多边形边选就行了  通过容斥会得到正确答案 #include<cmath> #include<cstdio> #include<algorithm> #define db double using namespace std; const int N=1e4+50; const db eps=1e-9; struct Point { db x,y;Point(){} Point(db _x,db _y) {

poj 3348 Cow 凸包面积

Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8122   Accepted: 3674 Description Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are f