hdu1392凸包裸题

 1 //极角排序
 2 #include <bits/stdc++.h>
 3 #define sqr(x) ((x)*(x))
 4 using namespace std;
 5 int n,st[200001],top;
 6 struct POI
 7 {
 8     int x,y;
 9     POI()
10     {
11         x=y=0;
12     }
13     POI(int _x,int _y)
14     {
15         x=_x;y=_y;
16     }
17 } p[200001];
18 int cross(POI x,POI y)
19 {
20     return x.x*y.y-x.y*y.x;
21 }
22 double dis(POI x,POI y)
23 {
24     return sqrt(sqr(x.x-y.x)+sqr(x.y-y.y));
25 }
26 POI operator-(POI x,POI y)
27 {
28     return POI(x.x-y.x,x.y-y.y);
29 }
30 bool com(POI x,POI y)
31 {
32     return(cross(x-p[1],y-p[1])>0 || cross(x-p[1],y-p[1])==0 && dis(x,p[1])<dis(y,p[1]));
33 }
34 int main()
35 {
36     for(scanf("%d",&n);n;scanf("%d",&n))
37     {
38         for(int i=1;i<=n;i++)
39             scanf("%d%d",&p[i].x,&p[i].y);
40         if(n==2)//wtf
41         {
42             printf("%.2f\n",dis(p[1],p[2]));
43             continue;
44         }
45         int id=1;
46         for(int i=2;i<=n;i++)
47             if(p[i].x<p[id].x || p[i].x==p[id].x && p[i].y<p[id].y) id=i;
48         swap(p[1],p[id]);
49         sort(p+2,p+n+1,com);
50         st[top=1]=st[0]=1;
51         for(int i=2;i<=n;i++)
52         {
53             while(top && cross(p[st[top]]-p[st[top-1]],p[i]-p[st[top]])<0) --top;
54             st[++top]=i;
55         }
56         double len=0;
57 //        puts("");
58 //        for(int i=1;i<=top;i++)
59 //            printf("%d %d\n",p[st[i]].x,p[st[i]].y);
60         st[++top]=1;
61         for(int i=1;i<top;i++)
62             len+=dis(p[st[i]],p[st[i+1]]);
63         printf("%.2f\n",len);
64     }
65     return 0;
66 }
时间: 2024-08-02 11:50:01

hdu1392凸包裸题的相关文章

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>

SZOJ 167 Lca裸题

一道.......一道我改了一周的裸题 无根树建双向边 无根树建双向边 无根树建双向边 重要的事情说三遍(微笑) 还有要开longlong 还有双向边不是双倍边(微笑) 我真是,能把自己气吐血10次就不把自己气吐血9次 [问题描述] 已知一棵nn个点的树,点从1开始标号,树上每条边都有一个正整数边权. 有qq个询问,每个询问由type,u,vtype,u,v三个正整数构成. 当type=1type=1时,询问uu到vv路径上所有边权的二进制异或和. 当type=2type=2时,询问uu到vv路

hdu 1348 Wall(凸包模板题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3386    Accepted Submission(s): 968 Problem Description Once upon a time there was a gre

hdu1159 poj1458 LCS裸题

HDU 1159 题意:找LCS 思路:裸题 n*m的写法,我的写法好像比较奇怪...用一个ci保存s2第i位可以做为s1的公共子序列的最大值,s1的每一位遍历s2,遍历的时候记录前面出现过的ci的最大值,ci一定是一个连序的上升序列,我的好像不是正经的LCS的算法,改天还是要学习一个的 AC代码: #include "iostream" #include "string.h" #include "stack" #include "qu

poj 1113 Wall(标准的凸包果题)

题目链接:http://poj.org/problem?id=1113 Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King's castle. The King was so greedy, that he would not listen to his Architect's proposals to build

HDU 4893 线段树裸题

Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2512    Accepted Submission(s): 751 Problem Description Recently, Doge got a funny birthday present from his new friend, Pro

POJ 3624 Charm Bracelet(01背包裸题)

Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 38909   Accepted: 16862 Description Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible fro

HDOJ-1232 畅通工程【并查集裸题】

题目传送门 : http://acm.hdu.edu.cn/showproblem.php?pid=1232 并查集的裸题 AC code: #include <iostream> #define MAXN 1050 using namespace std; int pre[MAXN]; int Find(int pos) { int r = pos; while (r != pre[r]) r = pre[r]; int i = pos; while (i != r) { int t = p

【不可能的任务22/200】【填坑】bzoj3224 splay裸题

人生第一道splay不出所料是一道裸题,一道水题,一道2k代码都不到的题 1 #include <cstdio> 2 int root,N=0,n,p,q; 3 int fa[100001],c[100001][2],size[100001],sp[100001]; 4 void rot(int x) 5 { 6 int y=fa[x],k=(c[y][0]==x); 7 size[y]=size[c[y][k]]+size[c[x][k]]+1;size[x]=size[c[x][!k]]+