• Codeforces Round #645 (Div. 2)


    A

    #include <bits/stdc++.h>
    #define all(n) (n).begin(), (n).end()
    #define se second
    #define fi first
    #define pb push_back
    #define mp make_pair
    #define sqr(n) (n)*(n)
    #define rep(i,a,b) for(int i=a;i<=b;++i)
    #define per(i,a,b) for(int i=a;i>=b;--i)
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef vector<int> VI;
    typedef double db;
     
    const int N = 1e5 + 5;
     
    int n, m, _, k;
     
    int main()
    {
        ios::sync_with_stdio(0); cin.tie(0);
        for (cin >> _; _; --_)
        {
            int a, b; cin >> a >> b;
            if (a % 2 == 0 || b % 2 == 0) cout << a * b / 2 << '
    ';
            else  cout << a * b / 2 + 1 << '
    ';
        }
        return 0;
    }
    

    B

    先排序, 全叫过来,再倒着判断是否能叫过来
    #include <bits/stdc++.h>
    #define all(n) (n).begin(), (n).end()
    #define se second
    #define fi first
    #define pb push_back
    #define mp make_pair
    #define sqr(n) (n)*(n)
    #define rep(i,a,b) for(int i=a;i<=b;++i)
    #define per(i,a,b) for(int i=a;i>=b;--i)
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef vector<int> VI;
    typedef double db;
     
    const int N = 1e5 + 5;
     
    int n, m, _, k;
    int a[N];
     
    int main()
    {
        ios::sync_with_stdio(0); cin.tie(0);
        for (cin >> _; _; --_)
        {
            cin >> n;
            rep (i, 1, n) cin >> a[i];
            sort(a + 1, a + 1 + n);
     
            int ans = 1 + n;
            for (int c = n; c && a[c] > ans - 1; --c, --ans);
            cout << ans << '
    ';
        }
        return 0;
    }
    

    C

    斜着看, 每向下走一步, +1

    #include <bits/stdc++.h>
    #define all(n) (n).begin(), (n).end()
    #define se second
    #define fi first
    #define pb push_back
    #define mp make_pair
    #define sqr(n) (n)*(n)
    #define rep(i,a,b) for(int i=a;i<=b;++i)
    #define per(i,a,b) for(int i=a;i>=b;--i)
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef vector<int> VI;
    typedef double db;
     
    const int N = 1e5 + 5;
     
    int n, m, _, k;
     
    int main()
    {
        ios::sync_with_stdio(0); cin.tie(0);
        for (cin >> _; _; --_)
        {
            ll x, y, a, b;
            cin >> x >> y >> a >> b;
            ll ans = (a - x) * (b - y) + 1;
            cout << ans << '
    ';
        }
        return 0;
    }
    

    D

    尺取法

    #include <bits/stdc++.h>
    #define all(n) (n).begin(), (n).end()
    #define se second
    #define fi first
    #define pb push_back
    #define mp make_pair
    #define sqr(n) (n)*(n)
    #define rep(i,a,b) for(int i=a;i<=b;++i)
    #define per(i,a,b) for(int i=a;i>=b;--i)
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef vector<int> VI;
    typedef double db;
     
    const int N = 2e5 + 5;
     
    ll n, m, _, k;
    ll a[N << 1];
    ll ans, sum[N << 1], s[N];
     
    int main()
    {
        ios::sync_with_stdio(0); cin.tie(0);
        cin >> n >> m;
        rep(i, 1, n) cin >> a[i], a[i + n] = a[i];
        rep(i, 1, (n << 1))
        {
            sum[i] = sum[i - 1] + a[i];
            if (i <= n) s[i] = s[i - 1] + (1 + a[i]) * a[i] / 2;
        }
     
        for (int l = 1, r = 1; l <= n; ++l)
        {
            while (r < (n + l - 1) && sum[r] - sum[l - 1] < m) ++r;
     
            if (sum[r] - sum[l - 1] == m)
            {
                ll res;
                if (r > n) res = s[r - n] + s[n] - s[l - 1];
                else res = s[r] - s[l - 1];
     
                ans = max(ans, res);
            }
            else if (r != l)
            {
                ll res;
                if (r - 1 > n) res = s[r - 1 - n] + s[n] - s[l - 1];
                else res = s[r - 1] - s[l - 1];
     
                ll cnt = m - (sum[r - 1] - sum[l - 1]);
                ll ct = min(a[l], a[r] - cnt);
     
                ans = max(ans, res - (1 + ct) * (ct) / 2 + (1 + cnt + ct) * (cnt + ct) / 2);
            }
            else ans = max(ans, (a[r] - m + 1 + a[r]) * m / 2);
        }
        cout << ans;
        return 0;
    }
    

    E

    线段树,没调出来

  • 相关阅读:
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    chrome标签记录——关于各类性能优化
    JavaScript(二)——在 V8 引擎中书写最优代码
    JavaScript学习(一)——引擎,运行时,调用堆栈
    MySQL数据库操作生成UUID
    使用Spring MVC实现文件上传与下载
    敏捷过程(小规模团队敏捷开发)
    后台获取日期值,前台Js对日期进行操作
    搭建Spring相关框架后,配置信息文件头部出现红色小×错误。
  • 原文地址:https://www.cnblogs.com/2aptx4869/p/12970080.html
Copyright © 2020-2023  润新知