Timus Online Judge:1119. Metro
来源:互联网 发布:金红米i7手机数据参数 编辑:程序博客网 时间:2024/06/01 10:38
1119. Metro
Time limit: 0.5 second
Memory limit: 64 MB
Memory limit: 64 MB
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 calculate the length of the shortest route from the south-western corner of the grid to the north-eastern one.
Input
There are two integers in the first line: N and M (0 < N,M ≤ 1000) — west-east and south-north sizes of the grid. Nikifor starts his way from a crossroad which is situated south-west of the quarter with coordinates (1, 1). A Metro station is situated north-east of the quarter with coordinates (N, M). The second input line contains a number K (0 ≤ K ≤ 100) which is a number of quarters that can be crossed diagonally. Then K lines with pairs of numbers separated with a space follow — these are the coordinates of those quarters.
Output
Your program is to output a length of the shortest route from Nikifor's home to the Metro station in meters, rounded to the integer amount of meters.
Sample
3 231 13 21 2
383
Problem Author: Leonid Volkov
Problem Source: USU Open Collegiate Programming Contest October'2001 Junior Session
Problem Source: USU Open Collegiate Programming Contest October'2001 Junior Session
Tags: dynamic programming graph theory
Difficulty: 87 Printable version Submit solution Discussion (55)
All submissions (35730) All accepted submissions (10464) Solutions rating (4523)
All submissions (35730) All accepted submissions (10464) Solutions rating (4523)
这道题目简单地通过dp就能够完成:
place[i][j] = min(place[i-1][j],place[i][j-1])+100;
当,两点之间有捷径时,place[i][j]=place[i-1][j-1]+sqrt(2)*100;
这道题目有几个点:
1.注意坐标的问题,主要是各个点的坐标。
2.小心精度问题,尽量使用sqrt(2),之前我使用1.414然后就被卡住了。
3.最后四舍五入通过使用+0.5再取int。
好了,废话说完了,贴代码:
0 0
- Timus Online Judge:1119. Metro
- Timus Online Judge 哥德巴赫猜想
- Timus Online Judge 1033 Labyrinth
- Timus Online Judge:1225. Flags
- 1350. Canteen Timus Online Judge
- Timus 1119. Metro
- Timus 1119. Metro
- Timus Online Judge 1658 Sum of Digits
- Timus Online Judge 1982 Electrification Plan
- Timus Online Judge 1742 Team building
- Timus Online Judge 2045 Richness of words
- Timus Online Judge 1651 Shortest Subchain
- Timus Online Judge 1045 Funny Game
- Timus Online Judge 1966 Cycling Roads
- Timus Online Judge:1040. Airline Company
- Timus Online Judge:1820. Ural Steaks
- Timus Online Judge:1100. Final Standings
- 【Timus Online Judge 1132】 Square Root
- XML 解析
- Router
- IP地址,子网掩码,默认网关,路由,形象生动阐述
- 51. N-Queens
- js操作函数,判断传递参数合法性和个数
- Timus Online Judge:1119. Metro
- Android Studio(DDMS)中的那些招
- C#连接MySQL数据库
- 2.2 SimpleAdapter的使用
- linux-ln -s(链接)、mount(挂载)
- 创建线程的方法
- Quartz.net开源作业调度框架使用详解
- zynq的三种启动方式(JTAG,SD,QSPI)
- jsp的9大内置对象