日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CF#-931A】 Friends Meeting(思维)

發布時間:2023/12/10 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CF#-931A】 Friends Meeting(思维) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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

Note

In the first example the first friend should move by one to the right (then the meeting happens at point?4), or the second friend should move by one to the left (then the meeting happens at point?3). In both cases, the total tiredness becomes?1.

In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point?100, and the total tiredness becomes?1?+?1?=?2.

In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point?8, and the total tiredness becomes?1?+?2?+?3?+?1?+?2?=?9.

題目大意:

? ? ?數軸上有兩人分別在a,b兩點,每個人每走一個單位坐標,增加疲勞值,且遞增,如左邊的人走三步,疲勞值為1+2+3=6。兩個人都能走,現希望兩人碰面,且求兩個人的最小疲勞值的和。

解題報告:

? 其實很好想啦,如果距離是偶數,找中間點就是了。如果是奇數,那就先找中間點-1,然后單獨算一個人多走的一步。

這里的距離可以用他們的坐標的奇偶來看。是一樣的。

?

AC代碼:

#include<bits/stdc++.h>using namespace std; long long ans;int main() {int a,b;cin>>a>>b;int sum = a+b;int half;if(sum%2 == 0) {half = sum/2;sum = abs(half-a);for(int i = 1; i<=sum; i++) {ans +=i;}ans+=ans;}else {int i;half = sum/2;a=min(a,b);sum = abs(half-a);for(i = 1; i<=sum; i++) {ans+=i;}ans+=ans;ans+=i;}printf("%lld\n",ans);return 0 ; }

?

總結

以上是生活随笔為你收集整理的【CF#-931A】 Friends Meeting(思维)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 91麻豆视频网站 | 亚洲天堂免费在线观看视频 | 国产精欧美一区二区三区蓝颜男同 | 神马久久久久久久 | 人人澡人人干 | 亚洲视频在线观看免费 | 国产精品不卡一区二区三区 | 亚洲丁香色| 99成人| 欧美在线xxxx | 亚洲国产欧美在线观看 | 电影91久久久 | 一级黄色网 | av综合导航 | 国产九色在线 | 亚洲人成亚洲人成在线观看 | 日韩精彩视频 | 色屁屁草草影院ccyycom | 91在线观 | 日日噜噜噜 | 福利国产视频 | 特级丰满少妇一级aaa爱毛片 | 欧美三级又粗又硬 | 五月天青青草 | 青青草视频黄 | 亚洲xx网站 | 日韩三级黄色片 | 国产原创在线视频 | 一道本无吗一区 | yjizz国产 | 精品麻豆一区二区 | 成人免费毛片嘿嘿连载视频 | 欧美日韩视频一区二区 | 视频在线观看一区二区 | missav|免费高清av在线看 | 日韩欧美中文字幕一区 | 黄色91免费观看 | 久热久操 | 男人在线视频 | 日日爱影视 | 九色91蝌蚪 | 精品国产一二三 | 激情视频免费在线观看 | 农村寡妇一区二区三区 | 欧美视频在线观看 | 国产视频麻豆 | 亚洲精品国产欧美 | 综合久久久久综合 | 韩国av中文字幕 | 日本高清中文字幕 | 亚洲区免费 | 男女猛烈无遮挡 | 超碰.com| 人人人草| 日本一区二区三区在线视频 | 神马午夜51 | aaa在线| 激情文学综合网 | 三级黄色生活片 | 操碰在线视频 | 欧美丰满熟妇bbbbbb百度 | 亚洲综合在线中文字幕 | 久久久亚洲综合 | 精品人妻少妇嫩草av无码 | xxx在线播放| 高清二区 | 九色蝌蚪9l视频蝌蚪9l视频 | 国产精品高潮呻吟久久av野狼 | 久久国产经典 | 久久免费在线视频 | 色呦| 在线免费看mv的网站入口 | 四虎精品欧美一区二区免费 | 欧美一级视频免费观看 | 国产欧美一区二区三区另类精品 | 欧美美女性视频 | 韩国日本在线观看 | 99爱精品| 免费国产一区二区 | 嫩草午夜少妇在线影视 | 777777av| 日本一道本| 久久香蕉国产 | 99热香蕉| 打屁股外国网站 | 亚洲综合五月天婷婷丁香 | 精品无码三级在线观看视频 | 日韩专区av| 午夜私人影院 | 熟妇的味道hd中文字幕 | 特大黑人巨交性xxxx | 性xxxx视频播放免费 | 男男做的视频 | 大象传媒成人在线观看 | 欧美人与动性xxxxx杂性 | 欧美视频在线一区二区三区 | 少妇欧美激情一区二区三区 | 国产美女久久久久久 | 亚洲日本韩国在线 |