P2742 [USACO5.1] 圈奶牛Fencing the Cows /【模板】二维凸包
1.D. Exam in MAC2.B. Array Fix3.P2181 对角线4.P1142 轰炸5.P1355 神秘大三角6.P1325 雷达安装
7.P2742 [USACO5.1] 圈奶牛Fencing the Cows /【模板】二维凸包
8.P3194 [HNOI2008] 水平可见直线9.P4999 烦人的数学作业10.P2602 [ZJOI2010] 数字计数11.[ARC173A] Neq Number12.D. Birthday Gift13.C. Sasha and the Casino14.P8764 [蓝桥杯 2021 国 BC] 二进制问题15.P6824 「EZEC-4」可乐16.P4551 最长异或路径17.P2613 【模板】有理数取余18.P5960 【模板】差分约束19.P5367 【模板】康托展开20.P2657 [SCOI2009] windy 数21.G. GCD on a grid22.M. Triangle Construction23.P10337 [UESTCPC 2024] 操作序列24.P10320 勇气(Courage)25.P10252 线性变换26.P4145 上帝造题的七分钟 2 / 花神游历各国27.D. 方块游戏28.J. 上学29.P8774 [蓝桥杯 2022 省 A] 爬树的甲壳虫30.P8806 [蓝桥杯 2022 国 B] 搬砖31.B. Mashmokh and ACM32.G. D-Function33.数论里的欧拉定理,简单证明,非常简单34.G. Ultra-Meow35.P5520 [yLOI2019] 青原樱36.Bracket Sequences II题解
好难解释必然性感觉像模拟??
code
#include<bits/stdc++.h>
using namespace std;
int q[100005]={0};
struct node
{
double x,y;
}a[100005];
double dis(int b,int c)
{
node i=a[b],j=a[c];
return sqrt((i.x-j.x)*(i.x-j.x)+(i.y-j.y)*(i.y-j.y));
}
bool cmp(node b,node c)
{
if(b.x!=c.x) return b.x<c.x;
return b.y>c.y;//贪心地往小的圈
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].x>>a[i].y;
}
sort(a+1,a+n+1,cmp);
q[1]=1;
q[2]=2;
int top=2;
for(int i=3;i<=n;i++)//扫下边
{
while(top>1)
{
double x1=a[q[top]].x-a[q[top-1]].x,y1=a[q[top]].y-a[q[top-1]].y;
double x2=a[i].x-a[q[top]].x,y2=a[i].y-a[q[top]].y;
if(x1*y2-x2*y1<=0)top--;
else break;
}
q[++top]=i;
}
int top1=top;
q[++top]=n-1;
for(int i=n-2;i>=1;i--)//扫上边
{
while(top>top1)
{
double x1=a[q[top]].x-a[q[top-1]].x,y1=a[q[top]].y-a[q[top-1]].y;
double x2=a[i].x-a[q[top]].x,y2=a[i].y-a[q[top]].y;
if(x1*y2-x2*y1<=0)top--;
else break;
}
q[++top]=i;
}
double ans=0;
for(int i=1;i<=top;i++)
{
//printf("%d:%d\n",i,q[i]);
ans+=dis(q[i],q[i%top+1]);
}
printf("%.2lf",ans);
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~