POJ 3348 最直接的凸包问题

题目大意:

给定一堆树的点,找到能组合成的最大面积,一个物体占50面积,求最多放多少物体

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <algorithm>
 5 using namespace std;
 6 const double eps = 1e-10;
 7 const int N = 10005;
 8 double myabs(double x)
 9 {
10     return x>0?x:-x;
11 }
12 struct Point{
13     double x,y;
14     Point(double x=0 , double y=0):x(x),y(y){}
15 };
16 Point p[N] , ch[N];
17 typedef Point Vector;
18 Vector operator+(Vector a , Vector b){
19     return Vector(a.x + b.x , a.y + b.y);
20 }
21 Vector operator-(Point a , Point b){
22     return Vector(a.x - b.x , a.y - b.y);
23 }
24 Vector operator*(Vector a, double b){
25     return Vector(a.x*b , a.y*b);
26 }
27 Vector operator/(Vector a, double b){
28     return Vector(a.x / b , a.y/b);
29 }
30 int dcmp(double x){
31     if(myabs(x) < eps) return 0;
32     return x<0?-1:1;
33 }
34 bool operator==(Point a ,Point b){
35     return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0;
36 }
37 bool operator<( Point a , Point b){
38     return dcmp(a.x-b.x)<0 || (dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)<0);
39 }
40 double Cross(Vector a , Vector b){
41     return a.x*b.y - b.x*a.y;
42 }
43 double get_polexy_area(Point *p , int n){
44     double ans = 0;
45     for(int i=1;i<n-1;i++){
46         ans += Cross(p[i] - p[0] , p[i+1] - p[0]);
47     }
48     return ans / 2;
49 }
50 int ConvexHull(Point *p, int n) //凸包
51 {
52     sort(p, p+n);
53     n = unique(p, p+n) - p; //去重
54     int m = 0;
55     for(int i = 0; i < n; i++)
56     {
57         while(m > 1 && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <= 0) m--;
58         ch[m++] = p[i];
59     }
60     int k = m;
61     for(int i = n-2; i >= 0; i--)
62     {
63         while(m > k && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <= 0) m--;
64         ch[m++] = p[i];
65     }
66     if(n > 1) m--;
67     return m;
68 }
69 int main()
70 {
71     //freopen("test.in","rb",stdin);
72     int n;
73     while(~scanf("%d",&n)){
74         for(int i=0;i<n;i++){
75             scanf("%lf%lf" , &p[i].x , &p[i].y);
76         }
77         int m = ConvexHull(p,n);
78         double area = get_polexy_area(ch , m);
79         int ans = (int)(area/50);
80         printf("%d\n",ans);
81     }
82     return 0;
83 }
时间: 2024-10-03 10:54:48

POJ 3348 最直接的凸包问题的相关文章

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

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

水题.不过,题意..呵呵了.. 围一个凸包,求出面积,然后除以50就可以了. #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; const int MAXN=10500; struct point { int x,y; }p[MAXN]; int n; int ans[MAXN],st[MAXN]; int stop

poj 1228 Grandpa&#39;s Estate(凸包)

Grandpa's Estate Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11508   Accepted: 3188 Description Being the only living descendant of his grandfather, Kamran the Believer inherited all of the grandpa's belongings. The most valuable one

【POJ 2187】 Beauty Contest (凸包-Graham扫描算法)

[POJ 2187] Beauty Contest (凸包-Graham扫描算法) 找平面最远点对 数据很大 用暴力会T..我感觉-- 扫描出个凸包 然后枚举凸包上的点即可 没坑 int也可过 注意重边跟共线就行 代码下附赠几组数据 代码如下: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <vector> #include

POJ 3528 hdu 3662 三维凸包模板题

POJ 3528题:http://poj.org/problem?id=3528 HDU 3662:http://acm.hdu.edu.cn/showproblem.php?pid=3662 一个是求三维凸包面数,一个是求三维凸包表面积,都是很裸的. 贴代码: #include<stdio.h> #include<algorithm> #include<string.h> #include<math.h> #include<stdlib.h>

poj 3348(凸包面积)

Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8063   Accepted: 3651 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