【水讨论】#53 A. Square Earth?
来源:互联网 发布:大数据saas概念股龙头 编辑:程序博客网 时间:2024/06/09 11:08
有一个n为边长的正方形边上有两个点,问只能走正方形边界的情况下最短路程是多长(顺时针A到B或者逆时针A到B咯~)。
好吧……分情况讨论好了……
我们把这个正方形从左下到右上分为两半,然后——
1) 两个点在同侧的话,就坐标(x+y)的差即可,记住abs取绝对值
2) 在不同侧的话,就两个方向看看哪个小咯~一侧为x1+y1+x2+y2,另一侧就直接正方形周长4n来减去前面那个就好。
Code:
#include <cstdio>#include <memory>#include <cstring>#include <iostream>#include <algorithm>using namespace std;int main(){int n,x1,y1,x2,y2;cin>>n>>x1>>y1>>x2>>y2;int len1=x1+y1,len2=x2+y2; //if((x1-y1)*(x2-y2)>=0) dist=abs(x1+y1-x2-y2); // 两点在 y=x 同侧 //else dist=x1+y1+x2+y2;// 两点在 y=x 异侧 int dist=abs( x1+y1-( (x1-y1)*(x2-y2)>=0 ? (x2+y2):(-x2-y2) ) );cout<<min(dist,4*n-dist)<<endl;return 0;}
0 0
- 【水讨论】#53 A. Square Earth?
- A Square Perfect Square
- Codeforces 1A-Theatre Square(水)
- CodeForces 1 A.Theatre Square(水~)
- #define SQUARE(a)((a)*(a))
- CODEFORCES:A. Theatre Square
- A. Theatre Square
- 1A. Theatre Square
- A-Black Square
- A. Black Square
- 1A--Theatre Square
- 1A - Theatre Square
- 1A. Theatre Square
- A. Theatre Square
- A. Theatre Square
- 1A Theatre Square
- 1A. Theatre Square
- 1A. Theatre Square
- 大连实训总结
- 矩阵快速幂
- POJ 1177 Picture(扫描线求周长)
- 黑马程序员学习5
- C语言之二维数组
- 【水讨论】#53 A. Square Earth?
- C语言之一维数组
- UVALive 5025 Arranging Your Team
- Struts2 --如果想看源码 Struts源码
- UVA11205
- Count the digits of any input integers
- C语言之认识C
- 一些表达式的陷阱
- 设置tabhost位于底部的三种方法