zoukankan      html  css  js  c++  java
  • Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)A. 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
    找到中间数用求和公式算一下就行了
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <set>
    #include <map>
    #define INF 0x3f3f3f3f
    #define lowbit(x) (x&(-x))
    #define eps 0.00000001
    #define pn printf("
    ")
    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
    ", 1LL*(1+aa)*aa/2 + 1LL*(1+bb)*bb/2);
    }
  • 相关阅读:
    疫情控制
    2020 CSP-J 多校赛 Day 2 T2 题解
    三校联考-水题狂欢信心赛
    QBXT 提高组储备营 2020.夏 游记
    【题解】(我出的题)XM捡面筋
    【题解】P4025 [PA2014]Bohater
    【题解】1644:【例 4】佳佳的 Fibonacci
    【题解】CF1165F2 Microtransactions (hard version)
    P2261 [CQOI2007]余数求和
    OVO——扶咕咕的20道CF
  • 原文地址:https://www.cnblogs.com/HazelNut/p/8621331.html
Copyright © 2011-2022 走看看