麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

POJ3348-凸包

2019-11-14 09:43:48
字體:
來源:轉載
供稿:網友

題意:一片草地上有n課樹,現在你想用繩子圈出一個盡可能大的面積出來養牛。已知每只牛需要50單位的面積,問最多能養幾只牛。

1.按極角排序。

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>using namespace std;int n,stack[10010],top;const int maxn = 1e6+10;const double eps = 1e-8;struct Tpoint{ double x; double y;}list[10010];;int dblcmp(double p){ if(fabs(p)<eps) return 0; return p>0?1:-1;}double dist(Tpoint a, Tpoint b){ return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));}double Cross(Tpoint p0, Tpoint p1, Tpoint p2) { return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);}bool cmp(Tpoint p1, Tpoint p2){ double temp = Cross(list[0],p1,p2); int tt = dblcmp(temp); if(!tt) return dist(list[0],p1) < dist (list[0],p2); return tt>0;}void Graham(){ Tpoint p0 = list[0]; int k = 0; for(int i=1;i<n;i++){ if(p0.y>list[i].y || (p0.y==list[i].y && p0.x>list[i].x)){ p0 = list[i]; k = i; } } swap(list[k], list[0]); sort(list+1, list+n, cmp); stack[0] = 0; stack[1] = 1; top = 1; for(int i=2;i<n;i++){ while( dblcmp(Cross(list[stack[top-1]], list[stack[top]],list[i])<0)){ top--; } stack[++top] = i; }}void init(){ for(int i=0 ; i < n ; i++ ) scanf("%lf%lf",&list[i].x,&list[i].y); memset(stack,0,sizeof(stack));}void sov(){ double area = 0; for (int i = 0; i <= top; i++) area +=fabs(Cross(list[stack[(i+1)%(top+1)]],list[stack[i]],list[stack[0]])); PRintf ("%d/n", (int)area/100);}int main(){ while(~scanf("%d",&n)){ if(n == 1||n == 2) { printf("0/n");continue;} init(); Graham(); sov(); }}

2.按x排序。(x相同按y排序)

從小到大遍歷,走到最大是一半的凸包,然后從大到小在走一遍,另半個凸包

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>using namespace std;int n,stack[10010],top;const int maxn = 1e6+10;const double eps = 1e-8;struct Tpoint{ double x; double y;}list[10010];;int dblcmp(double p){ if(fabs(p)<eps) return 0; return p>0?1:-1;}double Cross(Tpoint p0, Tpoint p1, Tpoint p2) { return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);}bool cmp(Tpoint p1, Tpoint p2){ if(p1.y == p2.y) return p1.x < p2.x; return p1.y < p2.y;}void Graham(){ top = 1; for(int i = 0 ; i <= 2; i++) stack[i] = i; for(int i=2;i<n;i++){ while(top && dblcmp(Cross(list[stack[top-1]], list[stack[top]],list[i])<0)){ top--; } stack[++top] = i; } int len = top; stack[++top] = n-2; for(int i = n-3; i >= 0 ; i--){ while(top!=len && dblcmp(Cross(list[stack[top-1]], list[stack[top]],list[i])<0)) top--; stack[++top] = i; }}void init(){ for(int i=0 ; i < n ; i++ ) scanf("%lf%lf",&list[i].x,&list[i].y); memset(stack,0,sizeof(stack)); sort(list, list+n, cmp);}void sov(){ double area = 0; for (int i = 0; i <= top; i++) area +=fabs(Cross(list[stack[(i+1)%(top+1)]],list[stack[i]],list[stack[0]])); printf ("%d/n", (int)area/100);}int main(){ while(~scanf("%d",&n)){ if(n == 1||n == 2) { printf("0/n");continue;} init(); Graham(); sov(); }}
上一篇:在python中排序元組

下一篇:函數與數組

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 成人男女啪啪免费观看网站四虎 | 91情侣偷在线精品国产 | chinese-xvideos | 成码无人av片在线观看网站 | 精品国产一区二 | 中文字幕在线免费看 | 国产女厕一区二区三区在线视 | 欧美国产日韩在线观看成人 | 久久伊人精品热在75 | 在线成人看片 | 黑人三级毛片 | 欧美精品日日鲁夜夜添 | 伊人久久电影网 | 国产精品久久99精品毛片三a | 国产女厕一区二区三区在线视 | 激情国产视频 | avav在线播放 | 免费看欧美一级特黄a毛片 九色com | 欧洲精品久久久久69精品 | 午夜精品小视频 | 成人毛片免费视频 | 久久久久久久久久一本门道91 | 精品一区二区三区日本 | 成人福利视频在线观看 | 最新se94se在线欧美 | 国产精品久久久免费观看 | 黄色特级视频 | 日本中文字幕高清 | 国产精品一区二区日韩 | 一边吃奶一边摸下娇喘 | 一区二区三区四区视频在线观看 | 久久国产夫妻视频 | 全免费午夜一级毛片真人 | 久久丝袜脚交足黄网站免费 | 欧美亚洲一区二区三区四区 | 鲁久久 | 亚洲最大的成人网 | 免费久久久久久 | 国产免费一区二区三区网站免费 | 一级黄色影院 | 久久精品国产精品亚洲 |