zju_1453_凸包

// 这道题虽然是个模板题,但还是纠结了很久,主要原因是在hdu1392上有同样的题目,可惜hdu上忽略了n=2的情况,导致一直找不出buger

#include<iostream>

#include<cstdio>

#include<cmath>

#include<algorithm>

using namespace std;

 

struct node

{

double x,y;

}a[103],stack[103],flag;

int n;

 

double dis(node a,node b)

{

return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));

}

 

int sect(node a,node b,node c)

{

return (a.x-c.x)*(b.y-c.y)<(b.x-c.x)*(a.y-c.y);

}

 

int cmp(node a,node b)

{

return sect(a,b,flag)>1e-8;

}

 

double gram()

{

int top=1;

stack[0]=a[0];

stack[1]=a[1];

int i;

for(i=2;i<n;i++)

{

while(top>0&&sect(a[i],stack[top],stack[top-1])>1e-8)top--;

stack[++top]=a[i];

}

// printf("/n");

// for(i=0;i<=top;i++)

// printf("%d %d/n",stack[i].x,stack[i].y);

// printf("/n");

double ans=dis(stack[top],stack[0]);

for(i=0;i<top;i++)

ans+=dis(stack[i],stack[i+1]);

return ans;

}

 

int main()

{

while(scanf("%d",&n)!=EOF&&n)

{

flag.x=flag.y=100000.0;

int index,i;

for(i=0;i<n;i++)

{

scanf("%lf%lf",&a[i].x,&a[i].y);

if(a[i].x<flag.x||a[i].x==flag.x&&a[i].y<flag.y)

{

index=i;

flag=a[i];

}

}

if(n==1)

{

printf("0.00/n");

continue;

}

// else if(n==2)      在zju上这一步要去掉,因为题目是用绳子围起来的长度,hdu的测试数据有有误,

// {

// printf("%.2lf/n",dis(a[0],a[1]));

// continue;

// }

a[index]=a[0];

a[0]=flag;

sort(a+1,a+n,cmp);

// printf("/n");

// for(i=0;i<n;i++)

// printf("%d %d/n",a[i].x,a[i].y);

// printf("/n");

printf("%.2lf/n",gram());

}

return 0;

}

 

 

引用\[1\]:错误信息:FileNotFoundError: \[Errno 2\] No such file or directory: '../AutoFrame/temp/report.xlsx' 相对于当前文件夹的路径,其实就是你写的py文件所在的文件夹路径! python在对文件的操作时,需要特别注意文件地址的书写。文件的路径地址,需要相对于正在被执行的.py文件来说。 举例说明: 1、正在执行.py文件在最外层(运行run_main.py),被操作的文件在其他文件夹时 report_B文件地址写成:./applicatiom/A/B/report_B.xlsx report_C文件地址写成:./applicatiom/A/C/report_C.xlsx report_temp文件地址写成:./temp/report_temp.xlsx 2、正在执行.py文件在文件夹中(运行test_01.py),被操作的文件在文件夹下时 report_B文件地址写成:./B/report_B.xlsx report_C文件地址写成:./C/report_C.xlsx 3、正在执行.py文件在文件夹中(运行test_01.py),被操作的文件在其他文件夹下时 report_temp.xlsx文件地址写成:../../temp/report_temp.xlsx report.xlsx文件地址写成:../../report.xlsx 注意事项:对多个文件进行操作时,可执行文件.py文件一定要固定目录,否则需要改动文件路径,否则找不到文件 运行run_main.py,操作../../temp/report_temp.xlsx文件路径,出现报错: raise FileCreateError(e) xlsxwriter.exceptions.FileCreateError: \[Errno 2\] No such file or directory: '../../temp/report_temp.xlsx'。 引用\[2\]:路径引用错误,原路径是…/data/,使用的是相对路径 解决方案: 改为正确的相对路径,在vscode中复制正确的你想引用的文件的相对路径临时却简单的方式:更改为绝对路径 f = gzip.open('E:/mlnum/neural-networks-and-deep-learning/data/mnist.pkl.gz', 'rb')。 问题: FileNotFoundError: \[Errno 2\] No such file or directory: 'E:\\ZJU_study\\YOLO\\mmyolo-main\\mmyolo-main\\configs\\custom_dataset\\../yolov5_s-v61_syncbn_fast_8xb16-300e_coco.py' 回答: 这个错误是由于文件路径引用错误导致的。在你的代码中,文件路径'E:\\ZJU_study\\YOLO\\mmyolo-main\\mmyolo-main\\configs\\custom_dataset\\../yolov5_s-v61_syncbn_fast_8xb16-300e_coco.py'无法找到。请确保你的文件路径是正确的,并且相对于当前执行的.py文件来说是有效的。你可以使用绝对路径或者正确的相对路径来引用文件。 #### 引用[.reference_title] - *1* [Python之FileNotFoundError: [Errno 2] No such file or directory问题处理](https://blog.youkuaiyun.com/qq_41845402/article/details/128974839)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [FileNotFoundError: [Errno 2] No such file or directory](https://blog.youkuaiyun.com/kuake11/article/details/126111213)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值