URAL 1119Metro dp练习
来源:互联网 发布:数据分享网站 编辑:程序博客网 时间:2024/05/29 06:55
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.
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 c
题目很简单 但是要注意题目给出的是坐标 ,而坐标表示与我们平时的矩阵先行后列的习惯是相反地,故写入的时候要注意;
并且题目给的坐标都是块的坐标不是点的坐标 不注
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;double dp[1100][1100];int map1[1100][1100];int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF) { int k; scanf("%d",&k); for(int i = 0 ; i <= m; i++) for(int j = 0; j <= n; j++) map1[i][j] = 0; for(int i = 1; i <= k; i++) { int x,y; scanf("%d%d",&x,&y); map1[y][x] = 1; } dp[0][0] = 0; for(int i = 1; i <= m; i++) dp[i][0] = dp[i-1][0] + 100; for(int i = 1; i <= n; i++) dp[0][i] = dp[0][i-1] +100; double num = sqrt(2)*100; for(int i = 1; i <= m; i++) { for(int j = 1; j <= n; j++) { dp[i][j] = min(dp[i-1][j],dp[i][j-1])+100; if(map1[i][j] == 1) { dp[i][j] = min(dp[i][j],dp[i-1][j-1]+num); } } } printf("%.0f\n",dp[m][n]); } return 0;}
意也可能出错
0 0
- URAL 1119Metro dp练习
- Ural 1119 Metro(DP)
- Ural 1119 Metro(DP) .
- ural 1119 Metro dp水
- URAL 1119 Metro (DP动态规划)
- ural 1119. Metro dp
- Ural 1119. Metro DP+精度
- ural 1119. Metro(dp)
- URAL 1119 Metro
- ural 1119 Metro
- URAL 1119Metro
- Ural 1119 Metro
- URAL 1119. Metro(简单dp)
- URAL 1119 Metro (动态规划)
- URAL 1225Flags dp练习
- URAL 1017Staircases dp练习
- URAL 1009K-based Numbers dp练习
- URAL 1146Maximum Sum dp练习
- MFC 绘制半透明图片
- 屌丝giser成长记-大学篇
- Activity 主界面服务
- 逻辑运算符及循环语句
- Dotcms中文教程之一:管理(1、配置介绍)
- URAL 1119Metro dp练习
- cocos2dx 玩转Menu菜单
- Unity3D之Quaternion学习与应用
- C语言程序内存结构
- LeetCode题解:Remove Duplicates from Sorted Array
- for循环输出<九九乘法表>
- 【HDU1540】【线段树】【区间合并】【一个PushUp合并还有下去的时候取区间】【可作为模板】
- Win8.1 64位操作系统 安装itunes出错问题解决办法
- HDU 5038Grade