博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)A. Friends Meeting
阅读量:4975 次
发布时间:2019-06-12

本文共 1803 字,大约阅读时间需要 6 分钟。

Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1 = a, another one is in the point x2 = b.

Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1 + 2 + 3 = 6.

The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point.

Input

The first line contains a single integer a (1 ≤ a ≤ 1000) — the initial position of the first friend.

The second line contains a single integer b (1 ≤ b ≤ 1000) — the initial position of the second friend.

It is guaranteed that a ≠ b.

Output

Print the minimum possible total tiredness if the friends meet in the same point.

Examples
input
3 4
output
1
input
101 99
output
2
input
5 10
output
9 找到中间数用求和公式算一下就行了
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define INF 0x3f3f3f3f#define lowbit(x) (x&(-x))#define eps 0.00000001#define pn printf("\n")using namespace std;typedef long long ll;const int maxn = 1e5+7;int main(){ int a,b; scanf("%d%d",&a,&b); int mid = abs(a-b); int aa = mid/2 + mid%2, bb = mid/2; printf("%I64d\n", 1LL*(1+aa)*aa/2 + 1LL*(1+bb)*bb/2);}

 

转载于:https://www.cnblogs.com/HazelNut/p/8621331.html

你可能感兴趣的文章
VS2012 创建项目失败,,提示为找到约束。。。。
查看>>
设计类图
查看>>
类对象
查看>>
[Voice communications] 声音的滤波
查看>>
SQL语言之概述(一)
查看>>
软件建模——第9章 毕业论文管理系统—面向对象方法
查看>>
[SDOI2008]洞穴勘测
查看>>
Difference between Linearizability and Serializability
查看>>
IDEA使用操作文档
查看>>
UIView
查看>>
添加日期选择控件
查看>>
bzoj4765: 普通计算姬 (分块 && BIT)
查看>>
看完漫画秒懂区块链
查看>>
Oracle命令类别
查看>>
stc12c5a60s2驱动TEA5767收音机模块硬件调试总结
查看>>
vue中提示$index is not defined
查看>>
css选择器
查看>>
ASP.NET上传下载文件
查看>>
Galaxy Nexus 全屏显示-隐藏Navigation Bar
查看>>
Spring中使用Velocity模板
查看>>