ZOJ1073 POJ1450 Gridland 投机取巧版。。。

105 篇文章 0 订阅
14 篇文章 0 订阅
关于这题有很多方法,我这里用了最简单的方法,就是。。。在图上画出来找规律。。。好了大家不要这么无语。。。

在图上寻找规律后,容易看出,当M或N是偶数,或者都是偶数,最短距离为M*N。而当M和N都是奇数,则必有一条或以上的卸径,而最短距离是M*N-1+sqrt(2)。这个一定要画图才能说明白,有时间我补上图吧。我先上代码吧,吃饭去了。

对了,有人问为什么很多时候输入用iostream,输出用stdio,其实呢,你们看一下以下这个就知道为什么了

ifstream cin("data.txt");

以下为全部代码。。。

/*******************************************************************************
 * Author : Neo Fung
 * Email : neosfung@gmail.com
 * Last modified : 2011-07-17 10:14
 * Filename : ZOJ1073_POJ1450_Gridland.cpp
 * Description :	http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1037
					http://poj.org/problem?id=1450
 * *****************************************************************************/
// ZOJ1073_POJ1450_Gridland.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"



#include <fstream>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <vector>
#include <stack>
#include <deque>
#include <map>
#include <math.h>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory.h>

using namespace std;

int main(void)
{
	//ifstream cin("data.txt");
	int ncases,m,n;
	int i;
	double result;
	cin>>ncases;
	for(i =1;i<=ncases;++i)
	{
		cin>>m>>n;
		if(m%2 && n%2)
		{
			result = m*n -1 + sqrt(2.0);
		}
		else
		{
			result = m*n;
		}

		cout<<"Scenario #"<<i<<":"<<endl;
		printf("%.2f\n\n",result);
	}


	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值