Codeforces Beta Round #53
はい。
http://codeforces.com/contest/57
A. Square Earth?
ざっくりと大意
・スタートからゴールを(0,0)〜(n,n)の座標の外周部だけ移動して最短で到達する距離はいくつか??
方針のようなもの
・右回りか、左回りどちらか片方のまわり方でスタートからゴールまでの移動距離を出す。 ・2nを越えてたら移動距離-2n(実は反対周りの方が近かったっぽいような)。
#!/usr/bin/env python # -*- coding: UTF-8 -*- import time import sys, io import re, math #start = time.clock() (n,x1,y1,x2,y2)=map(int, raw_input().split()) #cnt=x1+y1+x2+y2 #print cnt if cnt<2*n else 2*n-cnt ans=0 if (x1==0 and x2==n) or (x1==n and x2==0): print n + min(n-y1+n-y2, y1+y2) elif (y1==0 and y2==n) or (y1==n and y2==0): print n + min(n-x1+n-x2, x1+x2) else: print abs(x1-x2)+abs(y1-y2)
456235のTsumimanさんをパクった。
今夜は風邪が酷くてまともな状態ではなかった。。まぁ風邪ではなくても自力で出来たかは疑問ですが。。。