hdu-1046(找规律)

 题意:给你一个n*m图,问你经过每个点然后回到起点最短距离。

题解:n和m很大,很明显需要找规律。画几个图,发现n和m只要有一个是偶数答案就是n*m,当n和m都是奇数时,发现答案是n*m-1+saqt(2),注意输出格式。

#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
#include <queue>
#include <math.h>
using namespace std;
int main()
{
	int t;scanf("%d",&t);
	int cas=1;
	while(t--)
	{
		long long n,m;cin>>n>>m;
		printf("Scenario #%d:\n",cas++);
		if(n%2&&m%2)printf("%.2lf\n",(double)(sqrt(2)+n*m-1));
		else printf("%.2lf\n",(double)n*m);
		cout<<endl;
	}
	return 0;
}


猜你喜欢

转载自blog.csdn.net/qq_37632935/article/details/80101988