zoukankan      html  css  js  c++  java
  • Codeforces Round #674 (Div. 3)C. Increase and Copy

    Codeforces Round #674 (Div. 3)C. Increase and Copy

    题意:
    一开始你有一个数字1,一次操作,你可以选择一个数字给它加1,或者复制一个数字加到数列的尾部。现在给你一个数字n,问你进行多少次操作,最少可以让整个数列的和大于等于n。
    思路:
    很容易想到,因该是先把1个数加到一定值,然后再复制。那么怎么找那个值呢。也可以从1到sqrt(n),然后找最小值。注意向上取整的方式,吃了没文化的亏。

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cmath>
    #include <cstdlib>
    #include <cstring>
    #include <string>
    #include <map>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <bitset>
    #include <set>
    #include <utility>
    #define inf 0x3f3f3f3f
    #define INF 0x3f3f3f3f3f3f3f3f
    #define mem(a, b) memset(a, b, sizeof(a))
    #define pb push_back
    #define ll long long
    using namespace std;
    const double PI = acos(-1.0);
    const int N = 2e5 + 10;
    const int mod = 998244353;
    ////////////////////////////////
    void solve()
    {
        ll n;
        cin >> n;
        ll ans = INF;
        for (int x = 1; x * x <= n; ++x)
        {
            ans = min(ans, x - 1 + (n - x+x-1) / x);
        }
        cout << ans << endl;
    }
    int main()
    {
        int t;
        cin >> t;
        while (t--)
        {
            solve();
        }
        return 0;
    }
    
    
  • 相关阅读:
    dedecms代码研究五
    dedecms代码研究四
    判断有没有真正点击打印
    SAP中删除假脱机请求
    商品扩地点不成功
    记录一些使用的abap小程序帮助开发
    sap abap 程序 中使用 FTP . <转载>
    SM37 后台调试
    ftp上传下载| 图片上传下载
    ALV调用的几个标准函数 <转自 思微随想>
  • 原文地址:https://www.cnblogs.com/Aracne/p/13920658.html
Copyright © 2011-2022 走看看