zoukankan      html  css  js  c++  java
  • Anton and Fairy Tale

    Anton and Fairy Tale

    思路

    瞎扯

    一开始猜了一个假结论从第m + 1天开始,每天结束的谷物会比前一天少一个,没仔细读题。。。

    正解

    我们打表发现,第m天结束后剩余的谷物是(n - m),并且从第m + 1天开始,当天结束时剩余的谷物会比上一天的谷物少,并且满足

    (sum[m + i] - sum[m + i - 1] = i),于是我们有了下面这个式子。

    (frac{(1 + i) * i}{2} >= n - m),我们就是要求这个最小满足要求的i,然后最后答案就是(m + i)

    一种特殊情况,当(m > n)的时候,一定是在第n天谷物全部没有。

    代码

    #include<bits/stdc++.h>
    
    using namespace std;
    
    typedef long long ll;
    
    ll n, m;
    
    ll clac(ll x) {
        return (1 + x) * x / 2 < n - m;
    }
    
    int main() {
        // freopen("in.txt", "r", stdin);
        cin >> n >> m;
        if(m > n)   cout  << n << "
    ";
        else {
            ll l = 0, r = 2e9;
            while(l < r) {
                ll mid = l + r >> 1;
                if(clac(mid))   l = mid + 1;
                else r = mid;
            }
            cout << l + m << endl;
        }
        return 0;
    }
    
  • 相关阅读:
    编译nginx
    MVPN技术原理
    python中_, __, __foo__区别及使用场景
    https双向认证(python)
    http keepalive test code(python)
    压缩 KVM 的 qcow2 镜像文件
    nohup python程序,print无输出
    Less(51)
    Less(50)
    Less(49)
  • 原文地址:https://www.cnblogs.com/lifehappiness/p/12837823.html
Copyright © 2011-2022 走看看