想看更多的解题报告: http://blog.csdn.net/wangjian8006/article/details/7870410
转载请注明出处:http://blog.csdn.net/wangjian8006
题目大意:给出一个n×m的矩阵,每个点可以朝上下左右,还有4个斜着的方向走
问从某点出发,走遍所有的点的最短距离,每个点只能经过一次
解题思路:模拟
#include <iostream> #include <math.h> using namespace std; int main(){ int n,m,i; int Case,flag; double sum,t=(double)sqrt(2.0); scanf("%d",&Case); for(i=1;i<=Case;i++){ scanf("%d%d",&n,&m); if(n*m%2) sum=n*m-1+t; else sum=n*m; printf("Scenario #%d:\n%.2lf\n\n",i,sum); } return 0; }