codeforces 883M. Quadcopter Competition 思路
3 seconds
256 megabytes
standard input
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?
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.
Print the length of minimal path of the quadcopter to surround the flag and return back.
1 5
5 2
18
0 1
0 0
8
#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 思路的更多相关文章
- Codeforces 1082C Multi-Subject Competition 前缀和 A
Codeforces 1082C Multi-Subject Competition https://vjudge.net/problem/CodeForces-1082C 题目: A multi-s ...
- Codeforces 845C. Two TVs 思路:简单贪心算法
题目: 题目原文链接:http://codeforces.com/contest/845/problem/C 题意:现在我们有一个电视清单,有两个电视,电视清单上有每一个节目的开始时间和结束时间. 电 ...
- Codeforces 1082C Multi-Subject Competition(前缀+思维)
题目链接:Multi-Subject Competition 题意:给定n名选手,每名选手都有唯一选择的科目si和对应的能力水平.并且给定科目数量为m.求选定若干个科目,并且每个科目参与选手数量相同的 ...
- codeforces div2 C题思路训练【C题好难,我好菜】
1017C The Phone Number: 构造数列使得LIS和LDS的和最小,定理已知LIS=L,LDS=n/L的向上取整,根据样例可以得到设置L=根号n,构造方法如样例 截断法构造,不用考虑边 ...
- Codeforces.1110E.Magic Stones(思路 差分)
题目链接 听dalao说很nb,做做看(然而不小心知道题解了). \(Description\) 给定长为\(n\)的序列\(A_i\)和\(B_i\).你可以进行任意多次操作,每次操作任选一个\(i ...
- Codeforces.1082E.Increasing Frequency(思路)
题目链接 \(Description\) 给定\(n\)个数.你可以选择一段区间将它们都加上或减去任意一个数.求最终序列中最多能有多少个数等于给定的\(C\). \(n\leq5\times10^5\ ...
- Codeforces.1040E.Network Safety(思路 并查集)
题目链接 \(Description\) 有一张\(n\)个点\(m\)条边的无向图,每个点有点权.图是安全的当且仅当所有边的两个端点权值不同.保证初始时图是安全的. 现在有权值为\(x\)的病毒,若 ...
- Codeforces.838D.Airplane Arrangements(思路)
题目链接 \(Description\) 飞机上有n个位置.有m个乘客入座,每个人会从前门(1)或后门(n)先走到其票上写的位置.若该位置没人,则在这坐下:若该位置有人,则按原方向向前走直到找到空座坐 ...
- Codeforces 845A. Chess Tourney 思路:简单逻辑题
题目: 题意:输入一个整数n,接着输入2*n个数字,代表2*n个选手的实力. 实力值大的选手可以赢实力值小的选手,实力值相同则都有可能赢. 叫你把这2*n个选手分成2个有n个选手的队伍. ...
随机推荐
- Oracle:sqlplus前缀显示当前用户
第一步:进入SQLPLUS的按照目录,cd $ORACLE_HOME/sqlplus/admin 第二步:查找ll vi glogin.sql 第三步:插入 命令行模式,Go, set sq ...
- MongoDB备份恢复与导出导入
说明:本文所有操作均在win7下的MongoDB3.4.4版本中进行. 一.备份与恢复 1. 备份: mongodump -h IP --port 端口 -u 用户名 -p 密码 -d数据库 -o 文 ...
- R学习笔记 第四篇:函数,分支和循环
变量用于临时存储数据,而函数用于操作数据,实现代码的重复使用.在R中,函数只是另一种数据类型的变量,可以被分配,操作,甚至把函数作为参数传递给其他函数.分支控制和循环控制,和通用编程语言的风格很相似, ...
- WPF获得全局窗体句柄,并响应全局键盘事件
场景 wpf窗体运行后,只能捕获当前Active窗体的按键事件,如果要监听windows全局事件,并对当前窗口事件响应. 第一步:导入Winows API public class Win32 { [ ...
- 2_认识STM32库
2_认识STM32库 STM32库是由ST公司针对STM32提供的函数接口API,开发者可以调用这些函数接口来配置STM32的寄存器,使得开发人员得以脱离最底层的寄存器操作,开发快速. 库是架设在寄存 ...
- Java基础——字符串构建器
StringBuilder类: 可以将许多小段的字符串构建一个字符串. StringBuilder builder = new StringBuilder(); //构造一个空的字符串构建器 buil ...
- HTML的语法
1,什么是HTML标记语言,他是表示网页信息的符号标记语言,特点包括: a,可以设置文本的格式,比如标题,文号,文本颜色,段落等待 b,可以简历列表 c,可以插入图像和媒体 d,可以建立表格 e,超连 ...
- AngularJS学习篇(十七)
AngularJS 输入验证 <!DOCTYPE html> <html> <script src="http://apps.bdimg.com/libs/an ...
- AngularJS学习篇(十三)
AngularJS HTML DOM ng-disabled 指令 ng-disabled 指令直接绑定应用程序数据到 HTML 的 disabled 属性. <!DOCTYPE html> ...
- web前端免费资源集
web前端免费资源集 https://github.com/vhf/free-programming-books/blob/master/free-programming-books-zh.md