栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3716 Ribbon Gymnastics

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3716 Ribbon Gymnastics

#include <iostream>#include <iomanip>#include <sstream>#include <string>#include <cstdio>#include <algorithm>#include <cstring>#include <cctype>#include <cmath>#include <vector>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>#define ee 1e-10using namespace std;struct data{ int x,y; double dis;};double a[10][2];data d[10];double f[10][10];int tot;double calc(int i,int j){ double dx=a[i][0]-a[j][0],dy=a[i][1]-a[j][1]; return sqrt(dx*dx+dy*dy);}int dcmp(double x){ if (fabs(x)<ee) return 0;else return x<0?-1:1;}int main(){ while (cin>>a[0][0]>>a[0][1]) { for (int i=1;i<=3;i++) cin>>a[i][0]>>a[i][1]; tot=0; for (int i=0;i<4;i++) for (int j=i+1;j<4;j++) { f[i][j]=f[j][i]=calc(i,j); tot++; d[tot].x=i; d[tot].y=j; d[tot].dis=f[i][j]; } for (int i=1;i<6;i++) for (int j=i+1;j<=6;j++) if (dcmp(d[i].dis-d[j].dis)>0) swap(d[i],d[j]); if (d[1].x+d[1].y+d[2].x+d[2].y==6) { printf("%.7lfn",d[1].dis+d[2].dis); } else { int p1,p2,p3,p4; if (d[1].x==d[2].x) { p1=d[1].x; p2=d[1].y; p3=d[2].y; } if (d[1].x==d[2].y) { p1=d[1].x; p2=d[1].y; p3=d[2].x; } if (d[1].y==d[2].x) { p1=d[1].y; p2=d[1].x; p3=d[2].y; } if (d[1].y==d[2].y) { p1=d[1].y; p2=d[1].x; p3=d[2].x; } p4=6-p1-p2-p3; double tmp1=f[p2][p4]-f[p1][p2]; double tmp2=f[p3][p4]-f[p1][p3]; double tmp3=f[p1][p4]+f[p2][p3]-f[p1][p2]-f[p1][p3]; if (dcmp(tmp2-tmp1)<0) tmp1=tmp2; if (dcmp(tmp3-tmp1)<0) tmp1=tmp3; if (dcmp(f[p1][p4]-tmp1)<0) tmp1=f[p1][p4]; printf("%.7lfn",f[p1][p2]+f[p1][p3]+tmp1); } } return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/373892.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号