1046


Gridland

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

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


#include<iostream>
#include<stdio.h>
#include<cmath>
#include<algorithm>
using namespace std;
int cmp(int a,int b)
{
return a<b;

}
int main()
{
int i,j,m,n,cas;
float len;
int a[2];
cin>>n;
cas=0;
while(n--)
{
cin>>a[0]>>a[1];
sort(a,a+2,cmp);
if(a[0]==1)
len=a[1]-1;
if(a[0]==2)
len=a[0]*a[1];
else
{
if((a[0]*a[1])%2==0)
len=a[0]*a[1];
else
len=a[0]*a[1]-1+sqrt(2);

}

cas++;
printf("Scenario #%d:\n",cas);
if(n>=0)
{
printf("%.2f\n",len);
cout<<endl;
}
//else
//printf("%.2f\n",len);

}
return 0;
}

1046

时间: 2024-11-13 04:23:02

1046的相关文章

BZOJ 1046: [HAOI2007]上升序列 LIS -dp

1046: [HAOI2007]上升序列 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3438  Solved: 1171[Submit][Status][Discuss] Description 对于一个给定的S={a1,a2,a3,…,an},若有P={ax1,ax2,ax3,…,axm},满足(x1 < x2 < … < xm)且( ax1 < ax2 < … < axm).那么就称P为S的一个上升序列.如果有多

【BZOJ】【1046】【HAOI2007】上升序列

DP+贪心 啊……其实是个水题,想的复杂了 令f[i]表示以 i 为起始位置的最长上升子序列的长度,那么对于一个询问x,我们可以贪心地从前往后扫,如果f[i]>=x && a[i]>last,则x--,last=a[i] 保证$x_i$(下标)字典序最小…… 1 /************************************************************** 2 Problem: 1046 3 User: Tunix 4 Language: C++

[2016-05-09][51nod][1046 A^B Mod C]

时间:2016-05-09 21:28:03 星期一 题目编号:[2016-05-09][51nod][1046 A^B Mod C] 题目大意:给出3个正整数A B C,求A^B Mod C. 分析:直接快速幂 #include<stdio.h> using namespace std; typedef long long ll; ll pow_mod(ll a,ll p,ll mod){ ll ans = 1; while(p > 0){ if(p & 1){ ans = (

【BZOJ】1046 : [HAOI2007]上升序列

1046: [HAOI2007]上升序列 题意:给定S={a1,a2,a3,…,an}问是否存在P={ax1,ax2,ax3,…,axm},满足(x1 < x2 < … < xm)且( ax1 < ax2 < … < axm),若存在多组符合长度为m的递增子序列,则输出以序号字典序最小的:并非是数值 Sample Input 6 3 4 1 2 3 6 3 6 4 5 Sample Output Impossible 1 2 3 6 Impossible 数据范围 N&

Sicily 1046. Plane Spotting 解题报告

1046_Plane_Spotting 题目链接: http://soj.me/1046 题目大意: 给出序号为1,2,3...的时间段和每段时间上出现的飞机次数,找出几个连续的时间段,如2-5,其中持续的长度要大于或者等于题目要求.按照以下的要求来筛选出几个最优的时间段,如果达到要求的数量不够则全部输出,符合以下要求视为时间段p1优于p2: p1平均每段时间出现的飞机数大于p2,要求精度是double 平均每段时间出现飞机数一样,但是p1的持续时间比p2长 平均每段时间出现飞机数一样且持续时间

九度oj 题目1046:求最大值

题目1046:求最大值 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:11782 解决:4789 题目描述: 输入10个数,要求输出其中的最大值. 输入: 测试数据有多组,每组10个数. 输出: 对于每组输入,请输出其最大值(有回车). 样例输入: 10 22 23 152 65 79 85 96 32 1 样例输出: max=152 1 #include <iostream> 2 #include <vector> 3 #include <algorithm&g

【BZOJ 1046】 1046: [HAOI2007]上升序列

1046: [HAOI2007]上升序列 Description 对于一个给定的S={a1,a2,a3,-,an},若有P={ax1,ax2,ax3,-,axm},满足(x1 < x2 < - < xm)且( ax1 < ax2 < - < axm).那么就称P为S的一个上升序列.如果有多个P满足条件,那么我们想求字典序最小的那个.任务给出S序列,给出若干询问.对于第i个询问,求出长度为Li的上升序列,如有多个,求出字典序最小的那个(即首先x1最小,如果不唯一,再看x2

【NOIP1999】【Codevs 1046】旅行家的预算

http://codevs.cn/problem/1046/ Solution: 贪心,如果当前油价很低,它就比起当前剩余油的价还低就可以替换,并且每次加满,最后把剩的油卖掉即可 油价用单调链表(不知到为什么会写链表,脑抽,当时觉得插入方便,其实不用插入...尴尬)维护 or 堆(你也可以脑抽,加个log),没事啦,数据水 // <travel.cpp> - 06/23/16 12:55:15 // This file is made by YJinpeng,created by XuYike

POJ 1046 Color Me Less 最详细的解题报告

题目来源:POJ 1046 Color Me Less 题目大意:每一个颜色由R.G.B三部分组成,D=Math.sqrt(Math.pow((left.red - right.red), 2)+ Math.pow((left.green - right.green), 2)+ Math.pow((left.blue - right.blue), 2)) 表示两个不同颜色的之间的距离(以left和right为例,left和right分别为两种不同的颜色),现给出16组目标颜色,剩下的为待匹配的颜

1046 A^B Mod C(快速幂取模)

1046 A^B Mod C(51NOD基础题) 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 给出3个正整数A B C,求A^B Mod C. 例如,3 5 8,3^5 Mod 8 = 3. Input 3个正整数A B C,中间用空格分隔.(1 <= A,B,C <= 10^9) Output 输出计算结果 Input示例 3 5 8 Output示例 3 /* 1046 A^B Mod C(快速幂取模) 给出3个正整数A B C,求A^B Mod C. (