题目:如图所看到的的蜂巢型的图中。蜜蜂想从A点飞到B点,假设A与B不在同一个正六边形中,

则它先飞到A的中心。每次飞到相邻格子的中心,最后飞到B的中心,再飞到B点;

假设在一个格子中。直接飞过去就可以(观察第二组数据)。

分析:计算几何。

设格子边长为a。

首先观察,全部格子的中心为(3xa/2,sqrt(3)ya/2),当中x、y为整数且奇偶性同样;

因此。依据给定点的坐标,能够求出A,B所在的格子的行列编号(处理奇偶性不同情况)。

(因为,是取整计算,所以要要推断周围六个格子。是不是比自己更适合);

然后计算就可以。当中:(观察能够发现仅仅有数值和斜着走两种方式)

设x为横坐标编号差。y为纵坐标编号差;

假设。x >= y 则每次斜着走一定走到。所以中间路径长度为sqrt(3)*a*x。

否则,x < y 则多余的y要竖直方形行走。中间路径长度为sqrt(3)*a*((y-x)/ 2+r);

说明:注意编号奇偶同一时候的处理。

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath> using namespace std; typedef struct pnode
{
double x,y;
}point;
point a,b; typedef struct snode
{
int r,l;
}place;
place p,q; point getpoint(int r, int l, double L)
{
point p;
p.x = r*1.5*L;
p.y = l*sqrt(3.0)/2.0*L;
return p;
} double dist(point p, point q)
{
return sqrt((p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y));
} int dxy[7][2] = {{0,0},{0,2},{-1,1},{1,1},{-1,-1},{1,-1},{0,-2}};
place getplace(point a, double L)
{
int r = (int)(2*a.x/L/3.0);
int l = (int)(2*a.y/L/sqrt(3.0));
if (r%2 != l%2) {
l = l+l%2;
r = r+r%2;
}
int now = 0;
for (int i = 1 ; i < 7 ; ++ i)
if (dist(a, getpoint(r+dxy[i][0], l+dxy[i][1], L))
< dist(a, getpoint(r+dxy[now][0], l+dxy[now][1], L)))
now = i;
place s;
s.r = r+dxy[now][0];
s.l = l+dxy[now][1]; return s;
} int main()
{
double L,path,d1,d2;
while (~scanf("%lf%lf%lf%lf%lf",&L,&a.x,&a.y,&b.x,&b.y) && L) {
p = getplace(a, L);
q = getplace(b, L);
d1 = dist(a, getpoint(p.r, p.l, L));
d2 = dist(b, getpoint(q.r, q.l, L));
int r = abs(p.r-q.r),l = abs(p.l-q.l); if (r >= l)
path = r*L*sqrt(3.0);
else path = ((l-r)/2+r)*L*sqrt(3.0); if (r+l) printf("%.3lf\n",path+d1+d2);
else printf("%.3lf\n",path+dist(a,b));
}
return 0;
}

UVa 1531 - Problem Bee的更多相关文章

  1. uva 10034 Problem A: Freckles

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  2. uva 10032 Problem F: Tug of War

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  3. uva 10026 Problem C: Edit Step Ladders

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  4. (DP)uva 10036 Problem C: Divisibility

    链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88171#problem/F 代码: #include <cstdio> ...

  5. uva 10036 Problem C: Divisibility

    题意:能否在一个整数序列的每相邻的两项之间添加一个加减号,使得最终结果能被一个给定整数K<=100整除. dp[i][j]表示第i个数取余k为j的布尔值. #include <cstdio ...

  6. uva 11400 Problem F Lighting System Design

    紫皮书题: 题意:让你设计照明系统,给你n种灯泡,每种灯泡有所需电压,电源,每个灯泡的费用,以及每个灯泡所需的数量.每种灯泡所需的电源都是不同的,其中电压大的灯泡可以替换电压小的灯泡,要求求出最小费用 ...

  7. PC/UVa 题号: 110106/10033 Interpreter (解释器)题解 c语言版

    , '\n'); #include<cstdio> #include<iostream> #include<string> #include<algorith ...

  8. UVa Live 4670 Dominating Patterns - Aho-Corasick自动机

    题目传送门 快速的通道I 快速的通道II 题目大意 给定一堆短串,和一个文本串,问哪些短串在文本串中出现的次数最多. 我觉得刘汝佳的做法,时间复杂度有问题.只是似乎这道题短串串长太短不好卡.比如给出的 ...

  9. UVa Live 3942 Remember the Word - Hash - 动态规划

    题目传送门 高速路出口I 高速路出口II 题目大意 给定若干种短串,和文本串$S$,问有多少种方式可以将短串拼成长串. 显然,你需要一个动态规划. 用$f[i]$表示拼出串$S$前$i$个字符的方案数 ...

随机推荐

  1. 谈谈JVM垃圾回收机制及垃圾回收算法

    一.垃圾回收机制的意义 Java语言中一个显著的特点就是引入了垃圾回收机制,使c++程序员最头疼的内存管理的问题迎刃而解,它使得Java程序员在编写程序的时候不再需要考虑内存管理.由于有个垃圾回收机制 ...

  2. python day one

    今日内容: python基础: 一 编程语言 什么是编程语言? 上面提及的能够被计算机所识别的表达方式即编程语言,语言是沟通的介质,而编程语言是程序员与计算机沟通的介质.在编程的世界里,计算机更像是人 ...

  3. CPU怎么计算1+1----CPU计算的电路基础

    从<十进制和二进制的运算---我所理解到的人类的运算的本质>这里我们知道,人类进行运算的本质是查表,并且我们存储的表是有限的.那么计算机是怎进行四则运算的呢,也是查表吗,肯定不是,今天,我 ...

  4. 启动myeclipse弹窗Please allow Subclipse team to receive anonymous usage statistics for this Eclipse intance

    Please allow Subclipse team to receive anonymous usage statistics for this Eclipse intance(翻译:请允许Sub ...

  5. 常量指针(pointer to constant)和指针常量(constant pointer)

    一个指针可以操作两个实体,一个是指针值(即地址),一个是间访值(即指向的实体).于是指针的常量性也分为两种:常量指针(pointer to constant)和指针常量(constant pointe ...

  6. 51node 1134 最长递增子序列 (数据结构)

    题意: 最长递增子序列 思路: 普通的$O(n^2)$的会超时.. 然后在网上找到了另一种不是dp的写法,膜拜一下,自己写了一下解释 来自:https://blog.csdn.net/Adusts/a ...

  7. [BZOJ] 1037 [ZJOI2008]生日聚会

    Time Limit: 10 Sec Memory Limit: 162 MB Submit: 3007 Solved: 1795 [Submit][Status][Discuss] Descript ...

  8. mysql性能优化工具mysqltuner使用

    1.下载:wget --no-check-certificate https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysq ...

  9. python多线程和多进程(一)

    一.多线程 Python的标准库提供了两个模块:_thread和threading,_thread是低级模块,threading是高级模块,对_thread进行了封装.绝大多数情况下,只需要使用thr ...

  10. loadrunner 添加负载机

    1.打开Controller 2. 添加负载 3. 配置参数 4.完成