Problem Bee UVA - 1531

问题

https://vjudge.net/problem/UVA-1531

分析

设 六边形边长为L,那么六边形的重心坐标是 ( x L , y 3 2 L ) (xL,y\frac{\sqrt{3}}{2}L) (xL,y23 L),x,y要奇偶性相同。
首先求出两个点的所在六边形的中心坐标,然后计算两个六边形的距离。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long LL;
const int maxn=100000+5;
const double eps=1e-6,sqrt3=sqrt(3.0);
int n,s,kase=0;
struct Center{
    int x,y;
    Center(int x=0,int y=0):x(x),y(y){}
}pa,pb;
double L,xa,ya,xb,yb;
int dx[]={0,1,1,-1,-1,0},dy[]={2,1,-1,1,-1,-2};

inline double distant(double t1,double t2,double t3,double t4){
    return sqrt((t3-t1)*(t3-t1)+(t4-t2)*(t4-t2));
}

inline Center getCenter(double x,double y,double &disx){
    int row=x/(1.5*L),col=y/(sqrt3*L/2);
    if((row-col)%2!=0){
        col++;
    }
    disx=distant(row*(1.5*L),col*(sqrt3*L/2),x,y);
    double t=disx;
    int fx=row,fy=col;
    for(int i=0;i<6;++i){
        int nx=row+dx[i],ny=col+dy[i];
        t=distant(nx*(1.5*L),ny*(sqrt3*L/2),x,y);
        if(t<disx-eps){
            disx=t;
            fx=nx;
            fy=ny;
        }
    }
    return Center(fx,fy);
}

inline Center getLine(){
    Center t;
    t.x=abs(pa.x-pb.x);
    t.y=abs(pa.y-pb.y);
    if(t.x>=t.y) return Center(t.x,0);
    else return Center(t.x,(t.y-t.x)/2);
}

int main(void){
    while(scanf("%lf%lf%lf%lf%lf",&L,&xa,&ya,&xb,&yb) && L>eps){
        double disa=0,disb=0;
        pa=getCenter(xa,ya,disa);
        pb=getCenter(xb,yb,disb);
        if(pa.x==pb.x && pa.y==pb.y){
            printf("%.3lf\n",distant(xa,ya,xb,yb));
            continue;
        }
        Center ans=getLine();
        printf("%.3lf\n",disa+disb+(L*sqrt3)*ans.x+(sqrt3*L)*ans.y);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值