日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

POJ3348 Cows【凸包+多边形求面积】

發布時間:2024/10/8 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ3348 Cows【凸包+多边形求面积】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?POJ3348Cows 凸包+多邊形求面積?

個人分類:?計算幾何凸包

Language:?Default

Cows

Time Limit:?2000MS?Memory Limit:?65536K
Total Submissions:?7633?Accepted:?3467

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 forced to save money on buying fence posts by using trees as fence posts wherever possible. Given the locations of some trees, you are to help farmers try to create the largest pasture that is possible. Not all the trees will need to be used.

However, because you will oversee the construction of the pasture yourself, all the farmers want to know is how many cows they can put in the pasture. It is well known that a cow needs at least 50 square metres of pasture to survive.

Input

The first line of input contains a single integer,?n?(1 ≤?n?≤ 10000), containing the number of trees that grow on the available land. The next?n?lines contain the integer coordinates of each tree given as two integers?x?and?yseparated by one space (where -1000 ≤ x, y ≤ 1000). The integer coordinates correlate exactly to distance in metres (e.g., the distance between coordinate (10; 11) and (11; 11) is one metre).

Output

You are to output a single integer value, the number of cows that can survive on the largest field you can construct using the available trees.

Sample Input

4 0 0 0 101 75 0 75 101

Sample Output

151

題意:給出一些點,圈出一個最大面積,每50平方養一頭牛,問最多能養多少牛

求凸包 + (int)求面積 / 50

//POJ--1228 #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #define eps 1e-8 using namespace std;struct point {double x,y; }; point p[1010],stack[1010]; int N,top; //叉積 double multi(point p1, point p2, point p3) {return (p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x); } //距離公式 double dis(point a, point b) {return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } //極角排序比較器 bool cmp(point c, point d) {double k = multi(p[0], c, d);if(k>0) return true;if(k<0) return false;return dis(c,p[0])<dis(d,p[0]); } //求凸包 void Convex() {//第一個點p[0]為左下角的點for(int i = 1; i < N; i++){point temp;if(p[i].y < p[0].y || ( p[i].y == p[0].y && p[i].x < p[0].x)){temp = p[i];p[i] = p[0];p[0] = temp;}}sort(p + 1, p+N , cmp);//不包括第一個點stack[0] = p[0];stack[1] = p[1];top = 1;for(int i = 2; i < N; i++){while(top >= 1 && multi(stack[top - 1], stack[top], p[i]) < 0) top--;//共線的點也壓入凸包內;top++;stack[top] = p[i];} } //判斷每條邊是否有至少三個點; bool judge() {for(int i=1;i<top;i++){if((multi(stack[i-1],stack[i+1],stack[i]))!=0&&(multi(stack[i],stack[i+2],stack[i+1]))!=0)return false;}return true; } double area() {double res=0;for(int i=1;i<top;i++){res+=(multi(stack[0],stack[i],stack[i+1])/2.0);}return res; } int main() {while(scanf("%d",&N)!=EOF){for(int i=0;i<N;i++)scanf("%lf%lf",&p[i].x,&p[i].y);Convex();int num=(int)floor(area()/50.0);printf("%d\n",num);}return 0; }

?

總結

以上是生活随笔為你收集整理的POJ3348 Cows【凸包+多边形求面积】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。