Metro

原创 2016年08月28日 15:01:41

http://acm.timus.ru/problem.aspx?space=1&num=1119


Many of SKB Kontur programmers like to get to work by Metro because the main office is situated quite close the station Uralmash. So, since a sedentary life requires active exercises off-duty, many of the staff — Nikifor among them — walk from their homes to Metro stations on foot.
Problem illustration
Nikifor lives in a part of our city where streets form a grid of residential quarters. All the quarters are squares with side 100 meters. A Metro entrance is situated at one of the crossroads. Nikifor starts his way from another crossroad which is south and west of the Metro entrance. Naturally, Nikifor, starting from his home, walks along the streets leading either to the north or to the east. On his way he may cross some quarters diagonally from their south-western corners to the north-eastern ones. Thus, some of the routes are shorter than others. Nikifor wonders, how long is the shortest route.
You are to write a program that will calculate the length of the shortest route from the south-western corner of the grid to the north-eastern one.

题意:从左下角到右上角的最短路径长,地图上可以向上向右,有斜线的地方可以沿着斜线方向走。
分析:简单dp,从终点开始,最优解为左边一点+1,下边一点+1,左下一点+根号2(如果有边)的最小值。把最左边和最下边的点初始化一下比较方便。

题解:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <cstring>
#include <functional>
#include <cmath>
using namespace std;

bool path[1010][1010];
double dp[1010][1010];
int main()
{
	//freopen("in.txt", "r", stdin);
	int m, n;
	while (~scanf("%d %d",&n,&m))
	{
		memset(path, 0, sizeof(path));
		int k, x, y;
		scanf("%d", &k);
		for (int i = 0; i < k; i++)
		{
			scanf("%d %d", &x, &y);
			path[x][y] = true;
		}
		dp[0][0] = 0;
		for (int i = 1; i < n + 1; i++)
			dp[i][0] = dp[i - 1][0] + 1;
		for (int i = 1; i < m + 1; i++)
			dp[0][i] = dp[0][i-1] + 1;
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m;j++)
			{
				if (path[i][j]==true)
				{
					dp[i][j] = min(dp[i - 1][j] + 1, min(dp[i][j - 1] + 1, dp[i - 1][j - 1] + sqrt(2.0f)));
				}
				else
					dp[i][j] = min(dp[i - 1][j] + 1, dp[i][j - 1] + 1);
			}
		printf("%.f", dp[n][m] * 100);

	}
	return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

metro-jax-ws-jaxws221x.zip

  • 2017年10月31日 10:00
  • 45.74MB
  • 下载

win 8 桌面 metro 风格

  • 2015年04月10日 16:44
  • 87KB
  • 下载

超棒的 Windows 8 Metro UI 风格框架

这些资源包含:模板,框架,jQuery插件,图标集等。帮助你快速开发Windows 8 Metro UI风格的网站。 Frameworks & Templates For Metro-Style...
  • Joyhen
  • Joyhen
  • 2013年04月13日 10:59
  • 3131

Bootstrap Metro Dashboard

  • 2017年08月18日 15:03
  • 4.21MB
  • 下载

win8 metro 图标

  • 2013年08月15日 10:52
  • 946KB
  • 下载

【mahapps.metro】WPF窗体关闭,提示用户是否退出对话框

写在前面的话在项目中,通常我们会在用户选择退出系统时给出一定的提示,让用户确认是否退出。并且需要使窗体右上角的关闭按钮和我们自定义的关闭按钮行为相一致。这篇文章会逐步实现我们的目的。如何实现编写窗体C...

win8 metro 图标

  • 2013年10月25日 15:36
  • 3.59MB
  • 下载

Win8 Metro(C#)数字图像处理--2.65形态学轮廓提取算法

[函数名称]   形态学轮廓提取函数       WriteableBitmap MorcontourextractionProcess(WriteableBitmap src) //...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Metro
举报原因:
原因补充:

(最多只允许输入30个字)