zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 78 (Rated for Div. 2)B. A and B(1~n的分配)

    题:https://codeforces.com/contest/1278/problem/B

    思路:还是把1~n分配给俩个数,让他们最终相等

       假设刚开始两个数字相等,然后一个数字向前走了abs(b-a)步,由等差数列求和公式,这时候我们贪心的让另外一个数字走大于等于abs(b - a)的最小步数,然后如果两数相等必须满足走的步数之和%2=0

    #include<bits/stdc++.h>
    using namespace std;
    #define pb push_back
    typedef long long ll;
    const int M=1e6+5;
    ll a[10],countt[M];
    void solve()
    {
        ll a,b;
        cin>>a>>b;
        ll c=max(a,b)-min(a,b);
        int i;
        for(i=0;;i++)  
            if(c<=(i*(i + 1))/2) 
                break;
        ll m =(i*(i + 1))/2;
        while((m+c)% 2) 
            i++,m=(i*(i + 1))/2;
        cout<<i<<endl;
        return;
    }
    int main()
    {
        int t;cin>>t;
        while(t--)
            solve();
    }
    View Code
  • 相关阅读:
    占位博客
    占位博客
    占位博客
    占位
    占位
    占位
    占位
    占位
    python字典设置初始值setdefault()与get()
    自然语言处理如何入门
  • 原文地址:https://www.cnblogs.com/starve/p/12240511.html
Copyright © 2011-2022 走看看