Gridland

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4996    Accepted Submission(s): 2281

Problem Description
For years, computer scientists have been trying to find efficient solutions to different computing problems. For some of them efficient algorithms are already available, these are the “easy” problems like sorting, evaluating a polynomial or finding the shortest path in a graph. For the “hard” ones only exponential-time algorithms are known. The traveling-salesman problem belongs to this latter group. Given a set of N towns and roads between these towns, the problem is to compute the shortest path allowing a salesman to visit each of the towns once and only once and return to the starting point.

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.

 

Input

The first line contains the number of scenarios.

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.

 
Output
The output for each scenario begins with a line containing “Scenario #i:”, where i is the number of the scenario starting at 1. In the next line, print the length of the shortest traveling-salesman tour rounded to two decimal digits. The output for every scenario ends with a blank line.
 
Sample Input
2
2 2
2 3
 
Sample Output
Scenario #1:
4.00

Scenario #2:
6.00

 
Source
 
 #include <stdio.h>
#include <math.h> int main()
{
int t,i = ;
scanf("%d",&t);
while(t--)
{
double n,m;
scanf("%lf%lf",&n,&m); printf("Scenario #%d:\n",i++); if((int)n%== || (int)m%==)
printf("%.2lf\n",n*m);
else
printf("%.2lf\n",n*m-+sqrt(2.0));
printf("\n");
} return ;
}

poj 1450 Gridland的更多相关文章

  1. POJ 1450

    #include <iostream> using namespace std; int main() { //freopen("acm.acm","r&qu ...

  2. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  3. poj 题目分类(1)

    poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...

  4. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

  5. OpenJudge/Poj 1723 SOLDIERS

    1.链接地址: http://bailian.openjudge.cn/practice/1723/ http://poj.org/problem?id=1723 2.题目: 总时间限制: 1000m ...

  6. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  7. 转载:poj题目分类(侵删)

    转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码)  ...

  8. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  9. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

随机推荐

  1. JavaScript关闭浏览器

    (*^__^*) 嘻嘻……,以前我找关闭浏览器选项卡的代码找不到,我还以为要用后台代码关呢?今天发现只要简单2句JavaScipt代码就可以了.看来很多东西还是在于平时的积累啊的说! 模仿延儿的口气了 ...

  2. android——拍照,相册图片剪切其实就这么简单

    接触android这么久了.还没有真正的浩浩看看android拍照,相册图片剪切到底是怎么回事,每次都是从别人的代码一扣,就过来了.其实,谷歌提供的API已经很强大.只需要用的好,就那么几句就可以搞定 ...

  3. 个人的IDE制作(vim)——适用于C++/C

    引用文章A:http://learnvimscriptthehardway.onefloweroneworld.com/ 引用介绍:初学者建议通读一遍.对VIM能有整体性的了解. 引用文章B:http ...

  4. 用记事本编写C#程序并运行C#代码

    net framework自带有C#编译器 csc.exe,用它就好了 它在.NET框架目录下的<\Microsoft.NET\Framework\v**** (*号内容与版本有关) 不行你直接 ...

  5. 从汇编看c++多重继承中this指针的变化

    先来看一下下面的c++源码: #include <iostream> using namespace std; class X { public: virtual void print1( ...

  6. 理解ThreadLocal(一)

    早在JDK 1.2的版本中就提供java.lang.ThreadLocal,ThreadLocal为解决多线程程序的并发问题提供了一种新的思路.使用这个工具类可以很简洁地编写出优美的多线程程序. Th ...

  7. I/O事件

    I/O事件 最近在研究tornado和gevent,里面涉及了非阻塞I/O.在了解非阻塞I/O之前,需要先了解I/O事件 我们知道,内核有缓冲区.假设有两个进程A,B,进程B想读进程A写入的东西(即进 ...

  8. nginx---Beginner's Guide

    一 启动 nginx -s signal Where signal may be one of the following: stop — fast shutdown quit — graceful ...

  9. CodeForces 214B Hometask

    本题求n个数组成的大数,要求是2,3,5的倍数. 因为是2 和5 的倍数,所以个位为 0:所以若n个数中没有0,直接输出-1: 难点就是要求为3 的倍数. 因为若某个数为3的倍数,则其各位数的和必然是 ...

  10. Oracle EBS-SQL (OM-3):销售连接停靠站时冲减库存出错处理.sql

    DELETE FROM INV.MTL_RESERVATIONS MRWHERE EXISTS (SELECT 1 FROM WSH.WSH_DELIVERY_ASSIGNMENTS WDA      ...