题意:
本质就是要你用一根线将给定的点连起来,这根线最短是多少。
思路:
我在纸上画了[2 2][2 3][3 3][3 4][4 4][4 5][5 5][3 5]这几个例子。
从这几个例子就够找出规律了其实。然后写代码。一次AC。
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#define max(a,b) (a>b?a:b)
#define abs(a) ((a)>0?(a):-(a))
#define min(a,b) (a<b?a:b)
using namespace std;
int n,m;
int main()
{
int cases;
scanf("%d",&cases);
for(int i=1;i<=cases;i++)
{
scanf("%d%d",&n,&m);
if(n>m)
{
int t=m;
m=n;
n=t;
}
if(n%2&&m%2)
{
printf("Scenario #%d:\n%.2lf\n\n",i,n*m-1.0+sqrt(2.0));
}
else
{
printf("Scenario #%d:\n%.2lf\n\n",i,n*m+0.0);
}
}
return 0;
}