M. Quadcopter Competition
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:

  • start the race from some point of a field,
  • go around the flag,
  • close cycle returning back to the starting point.

Polycarp knows the coordinates of the starting point (x1, y1) and the coordinates of the point where the flag is situated (x2, y2). Polycarp’s quadcopter can fly only parallel to the sides of the field each tick changing exactly one coordinate by 1. It means that in one tick the quadcopter can fly from the point (x, y) to any of four points: (x - 1, y), (x + 1, y), (x, y - 1) or (x, y + 1).

Thus the quadcopter path is a closed cycle starting and finishing in (x1, y1) and containing the point (x2, y2) strictly inside.

The picture corresponds to the first example: the starting (and finishing) point is in (1, 5) and the flag is in (5, 2).

What is the minimal length of the quadcopter path?

Input

The first line contains two integer numbers x1 and y1 ( - 100 ≤ x1, y1 ≤ 100) — coordinates of the quadcopter starting (and finishing) point.

The second line contains two integer numbers x2 and y2 ( - 100 ≤ x2, y2 ≤ 100) — coordinates of the flag.

It is guaranteed that the quadcopter starting point and the flag do not coincide.

Output

Print the length of minimal path of the quadcopter to surround the flag and return back.

Examples
input
1 5
5 2
output
18
input
0 1
0 0
output
8
题意:
从起点出发,绕过旗子再回去,求最短的贿赂距离,只有上下左右四个方向。
解法:
起点、旗子确定一个矩形,出去绕开旗子距离+2,回来距离+2
当横或纵坐标有两个一样的,再+2,画图即可明白。
代码:
 #include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int x1,y1,x2,y2;
int ans=;
scanf("%d %d",&x1,&y1);
scanf("%d %d",&x2,&y2);
ans=(abs(x1-x2)+abs(y1-y2)+)<<;
if(!(x1-x2)||!(y1-y2)) ans+=;
printf("%d\n",ans);
return ;
}

codeforces 883M. Quadcopter Competition 思路的更多相关文章

  1. Codeforces 1082C Multi-Subject Competition 前缀和 A

    Codeforces 1082C Multi-Subject Competition https://vjudge.net/problem/CodeForces-1082C 题目: A multi-s ...

  2. Codeforces 845C. Two TVs 思路:简单贪心算法

    题目: 题目原文链接:http://codeforces.com/contest/845/problem/C 题意:现在我们有一个电视清单,有两个电视,电视清单上有每一个节目的开始时间和结束时间. 电 ...

  3. Codeforces 1082C Multi-Subject Competition(前缀+思维)

    题目链接:Multi-Subject Competition 题意:给定n名选手,每名选手都有唯一选择的科目si和对应的能力水平.并且给定科目数量为m.求选定若干个科目,并且每个科目参与选手数量相同的 ...

  4. codeforces div2 C题思路训练【C题好难,我好菜】

    1017C The Phone Number: 构造数列使得LIS和LDS的和最小,定理已知LIS=L,LDS=n/L的向上取整,根据样例可以得到设置L=根号n,构造方法如样例 截断法构造,不用考虑边 ...

  5. Codeforces.1110E.Magic Stones(思路 差分)

    题目链接 听dalao说很nb,做做看(然而不小心知道题解了). \(Description\) 给定长为\(n\)的序列\(A_i\)和\(B_i\).你可以进行任意多次操作,每次操作任选一个\(i ...

  6. Codeforces.1082E.Increasing Frequency(思路)

    题目链接 \(Description\) 给定\(n\)个数.你可以选择一段区间将它们都加上或减去任意一个数.求最终序列中最多能有多少个数等于给定的\(C\). \(n\leq5\times10^5\ ...

  7. Codeforces.1040E.Network Safety(思路 并查集)

    题目链接 \(Description\) 有一张\(n\)个点\(m\)条边的无向图,每个点有点权.图是安全的当且仅当所有边的两个端点权值不同.保证初始时图是安全的. 现在有权值为\(x\)的病毒,若 ...

  8. Codeforces.838D.Airplane Arrangements(思路)

    题目链接 \(Description\) 飞机上有n个位置.有m个乘客入座,每个人会从前门(1)或后门(n)先走到其票上写的位置.若该位置没人,则在这坐下:若该位置有人,则按原方向向前走直到找到空座坐 ...

  9. Codeforces 845A. Chess Tourney 思路:简单逻辑题

    题目: 题意:输入一个整数n,接着输入2*n个数字,代表2*n个选手的实力.    实力值大的选手可以赢实力值小的选手,实力值相同则都有可能赢.    叫你把这2*n个选手分成2个有n个选手的队伍. ...

随机推荐

  1. 启动tomcat爆错 the JRE could not be found

    启动报错,如下图: 之前更改了了一个较低的jdk的版本看了看一个项目的代码,不知所云,然后再改回来, 混乱之中只要启动Tomcat就出现这种错误,还是无法找到JRE,最后如此解决: 在Windows- ...

  2. LeetCode 257. Binary Tree Paths (二叉树路径)

    Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 ...

  3. 67、django之模型层(model)--查询补充及mookie

    本篇导航: F查询与Q查询 cookie 一.F查询与Q查询 1.以Book表为例 class Book(models.Model) : title = models.CharField(max_le ...

  4. HTTP Error 500.19 - Internal Server Error

    1.使用svn对项目进行管理 2.之前都是平安无事,忽然有一天报错:HTTP Error 500.19 - Internal Server Error,如图: 3.经过各种挣扎和求证,最后发现是项目. ...

  5. 机器学习之二:K-近邻(KNN)算法

    一.概述 K最近邻(k-Nearest Neighbor,KNN)分类算法,是一个理论上比较成熟的方法,也是最简单的机器学习算法之一.该方法的思路是:如果一个样本在特征空间中的k个最相似(即特征空间中 ...

  6. 1016: [JSOI2008]最小生成树计数

    1016: [JSOI2008]最小生成树计数 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 6200  Solved: 2518[Submit][St ...

  7. poj 2720 Last Digits

    Last Digits Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2233   Accepted: 474 Descri ...

  8. 文本宽度的测量--measureText

    HTML5中的canvas提供了文字宽度的测量方法: ctx.measureText(string).width var c=document.getElementById("myCanva ...

  9. 让盒子两端对齐小技巧 => inline-block

    今天在项目中碰到了设计盒子两端对齐的栗子,咱们用inline-block方法轻松的解决了,下面是我的经验: 原理: 利用文字text-align:justify; 操纵inline-block盒子,能 ...

  10. POI/Excel/HTML单元格公式问题

    一.问题描述 使用MyBatis从数据库中获取数据,然后用POI把数据填充到Excel模板中,生成最终的xls文件.把最终的xls文件转换为html文件,并返回给前台显示在Panel中. Excel模 ...