<span style="color:green;"></span>Metro<span id="crawlSuccess" style="display: inline;" class="crawlInfo"><strong>Time Limit:</strong><span id="timeLimit">500</span>MS <strong>Memory Limit:</strong><span id="memoryLimit">65536</span>KB <strong>64bit IO Format:</strong><span id="_64IOFormat">%I64d & %I64u</span></span><div id="problem_opt" style="font-size:12px;margin-top:10px"><a target=_blank role="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="submit"><span class="ui-button-text">Submit</span></a><a target=_blank role="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="problem_status" href="http://acm.hust.edu.cn/vjudge/contest/view.action?cid=61836#status//J/0"><span class="ui-button-text">Status</span></a></div><div style="960px;margin:auto"><div style="display: block;" class="hiddable" id="vj_description"><p class="pst">Description</p><div class="textBG"><div class="problem_par"><div class="problem_par_normal"> 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. </div></div><div class="problem_centered_picture"><img src="http://acm.timus.ru/image/get.aspx/8ad50e2a-2ca2-4898-87f4-83c9e9d70be3" alt="Problem illustration" border="0" /></div><div class="problem_par"><div class="problem_par_normal"> 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. </div></div><div class="problem_par"><div class="problem_par_normal"> 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. </div></div></div></div><div style="display: block;" class="hiddable" id="vj_input"><p class="pst">Input</p><div class="textBG"><div class="problem_par"><div class="problem_par_normal"> There are two integers in the first line: <em>N</em> and <em>M</em> (0 < <em>N</em>, <em>M</em> ≤ 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 ( <em>N</em>, <em>M</em>). The second input line contains a number <em>K</em> (0 ≤ <em>K</em> ≤ 100) which is a number of quarters that can be crossed diagonally. Then <em>K</em> lines with pairs of numbers separated with a space follow — these are the coordinates of those quarters. </div></div></div></div><div style="display: block;" class="hiddable" id="vj_output"><p class="pst">Output</p><div class="textBG"><div class="problem_par"><div class="problem_par_normal"> 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. </div></div></div></div><div style="display: block;" class="hiddable" id="vj_sampleInput"><p class="pst">Sample Input</p><div class="textBG"><table class="sample "><tbody><tr><th width="350">input</th><th width="350">output</th></tr><tr><td><pre class="intable">3 2 3 1 1 3 2 1 2
383
动态规划
/*************************************************************************> File Name: j.cpp> Author:yuan > Mail: > Created Time: 2014年11月10日 星期一 21时37分01秒 ************************************************************************/#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<cmath>using
namespace std;#define INF 0x3ffffffbool flag[1007][1007];double ans[1007][1007];int n,m,k;int main(){ while(~scanf("%d%d%d",&n,&m,&k)){ memset(flag,0,sizeof(flag)); // for(int i=0;i<1007;i++) // for(int j=0;j<1007;j++) // { // ans[i][j]=INF; // } for(int i=0;i<k;i++)
{ int aa,bb; scanf("%d%d",&aa,&bb); flag[bb+1][aa+1]=1; } ans[0][0]=0; for(int i=1;i<=n+1;i++) ans[0][i]=INF; for(int i=1;i<=m+1;i++) ans[i][0]=INF; n++;m++; for(int i=1;i<=m;i++) for(int j=1;j<=n;j++) { if(i==1&&j==1) continue; if(flag[i][j]) ans[i][j]=min(ans[i-1][j-1]+100*sqrt(2.0),min(ans[i-1][j]+100,ans[i][j-1]+100));
else ans[i][j]=min(ans[i-1][j]+100,ans[i][j-1]+100); } printf("%.0lf
",ans[m][n]); } return 0;}