HDU1046:Gridland
The president of Gridland has hired you to design a program that calculates the length of the shortest traveling-salesman tour for the towns in the country. In Gridland, there is one town at each of the points of a rectangular grid. Roads run from every town in the directions North, Northwest, West, Southwest, South, Southeast, East, and Northeast, provided that there is a neighbouring town in that direction. The distance between neighbouring towns in directions North–South or East–West is 1 unit. The length of the roads is measured by the Euclidean distance. For example, Figure 7 shows 2 × 3-Gridland, i.e., a rectangular grid of dimensions 2 by 3. In 2 × 3-Gridland, the shortest tour has length 6.
For each scenario, the grid dimensions m and n will be given as two integer numbers in a single line, separated by a single blank, satisfying 1 < m < 50 and 1 < n < 50.
2 2
2 3
4.00
Scenario #2:
6.00
一道规律题
当n,m有一者能够为偶数时,结果是n*m
否者必有一条路需要斜着走,结果为n*m-1+1.41
#include <stdio.h>
#include <math.h> int main()
{
int t,i = 1;
scanf("%d",&t);
while(t--)
{
double n,m;
scanf("%lf%lf",&n,&m);
printf("Scenario #%d:\n",i++);
if((int)n%2==0 || (int)m%2==0)
printf("%.2lf\n",n*m);
else
printf("%.2lf\n",n*m-1+sqrt(2.0));
printf("\n");
} return 0;
}
HDU1046:Gridland的更多相关文章
- POJ1450:Gridland 【杂题】
题目大意:先给出了TSP的背景,然后给出一个n*m的单位格点的图,图中除边缘上的点与八个方向的点有边连接,距离为欧拉距离,求从左上角出发的TSP 思路:从水题列表中看到的题,但看一开始给出的backg ...
- zust_第二周——瞎扯系列
首先来原题列表: A:Gridland http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1037 B:HangOver htt ...
- java web 开发三剑客 -------电子书
Internet,人们通常称为因特网,是当今世界上覆盖面最大和应用最广泛的网络.根据英语构词法,Internet是Inter + net,Inter-作为前缀在英语中表示“在一起,交互”,由此可知In ...
- 所有selenium相关的库
通过爬虫 获取 官方文档库 如果想获取 相应的库 修改对应配置即可 代码如下 from urllib.parse import urljoin import requests from lxml im ...
- Gridland(规律)
Gridland Time Limit: 2 Seconds Memory Limit: 65536 KB BackgroundFor years, computer scientists ...
- TJU Problem 1015 Gridland
最重要的是找规律. 下面是引用 http://blog.sina.com.cn/s/blog_4dc813b20100snyv.html 的讲解: 做这题时,千万不要被那个图给吓着了,其实这题就是道简 ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- In-Memory:内存数据库
在逝去的2016后半年,由于项目需要支持数据的快速更新和多用户的高并发负载,我试水SQL Server 2016的In-Memory OLTP,创建内存数据库实现项目的负载需求,现在项目接近尾声,系统 ...
- 从直播编程到直播教育:LiveEdu.tv开启多元化的在线学习直播时代
2015年9月,一个叫Livecoding.tv的网站在互联网上引起了编程界的注意.缘于Pingwest品玩的一位编辑在上网时无意中发现了这个网站,并写了一篇文章<一个比直播睡觉更奇怪的网站:直 ...
随机推荐
- Activity之间定时跳转
起源:很多应用在打开时,首先会加载欢迎页面,经过几秒后再跳转到主页面. 下面,我通过两种不同的方式来实现页面的定时跳转. 第一种方式: 通过Timer类的schedule方法. 实现从MainActi ...
- poj2636---Electrical Outlets(插线板)
#include <stdio.h> #include <stdlib.h> int main() { int n,nc,i; scanf("%d",&am ...
- iso-开发基础知识-1-程序流程
main-应用程序委托-视图控制器 main()---主函数 应用程序委托 ---AppDelegate 视图控制器 ---ViewController - (BOOL)applicatio ...
- saiku之固定维度(必选维度)
工作中遇到的问题,记录下来方便以后查找. 在saiku中如何设定固定维度? 找到WorkspaceDropZone.js文件,在synchronize_query: function(){}方法中的“ ...
- 在MyEclipse中统计项目行数
今天闲来无事就把自己曾经做过的一些小项目拿出来看一下,把一些自己觉得不好的地方又又一次改一下,突然想起有人说过大学生在毕业时至少要完毕多少代码才算合格,所以我就想统计一下自己做过的项目的代码量,在网上 ...
- 通过案例掌握Spring 管理事务的步骤及配置
案例描述 通过完成生成订单业务,掌握事务处理. 需要d_order表和d_item表 订单生成时的业务逻辑:向d_order插入1条数据的同时,向t_item中插入若干条数据 这就是一个独立的 ...
- .NET中TextBox控件设置ReadOnly=true后台取不到值 三种解决方法
方法一:不设置ReadOnly属性,通过onfocus=this.blur()来模拟,如下: <asp:TextBox ID="TextBox1" runat="s ...
- SQL Server索引进阶第十一篇:索引碎片分析与解决
相关有关索引碎片的问题,大家应该是听过不少,也许也很多的朋友已经做了与之相关的工作.那我们今天就来看看这个问题. 为了更好的说明这个问题,我们首先来普及一些背景知识. 知识普及 我们都知道,数据库中的 ...
- CentOS 安装Node.js
先安装gcc-c++编译环境和openssl yum install gcc-c++ openssl-devel 然后 下载包并解压 cd /usr/local/src wget http://nod ...
- js中的数组和字符串的一些方法
数组的一些方法: 1.join()和split()方法 <script type="text/javascript">var x;var a=new Array();a ...