• ABC136


    ABC136

    B

    枚举 1 ~ n ,判断位数是否是奇数即可。

    int solve(int n)
    {
        int ans = 0;
        while(n)
        {
           n /= 10;
           ans++;
        }
        return ans;
    }
    int main() {
        int n;
        cin >> n;
        int ans = 0;
        for (int i = 1; i <= n;i++)
        {
            if(solve(i) % 2)
                ans++;
        }
        cout << ans << endl;
        return 0;
    }
    
    

    C

    只要在 a[i] 前面的数比 a[i] 大于等于 2 时,那么不管前面的数怎么减 1 ,前面的数一定比 a[i] 要大,无法构成非下降序列。

    LL a[N];
    int main() {
        int n;
        cin >> n;
        rep(i,n) cin >> a[i];
        a[n + 1] = 2e9;
        LL maxn = 0;
        rep(i,n)
        {
            maxn = max(maxn, a[i]);
            if(maxn - a[i] > 1)
            {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }
    

    D

    考虑 R....L 构成一段答案的组成。

    RRRLLLRL 能够形成 RRRLLL,RL 两段序列,而且数字最终会聚集在 R,L 交界处。

    例子中最终答案必为:0,0,x,y,0,0,1,1 (x > 0,y > 0)

    其余都是 0

    考虑 (R...L) 这一段序列长度 sum

    sum % 2 == 0 最终交界处两端长度一样都是 sum / 2

    sum % 2 != 0 这里要考虑奇数偶数关系,考虑第一次数字全在交界处的移动次数,次数为奇数,那么最终答案要两边交换一下,因为 (10^{100}) 是偶数。

    #include <bits/stdc++.h> 
    #define SZ(X) ((int)(X).size())
    #define ALL(X) (X).begin(), (X).end()
    #define rep(I, N) for (int I = 1; I <= (N); ++I)
    #define repp(I, N) for (int I = 0; I < (N); ++I)
    #define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
    #define FORR(I, A, B) for (int I = (A); I >= (B); I--)
    #define SORT_UNIQUE(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
    #define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
    #define MP make_pair
    #define PB push_back
    #define MS0(X) memset((X), 0, sizeof((X)))
    #define MS1(X) memset((X), -1, sizeof((X)))
    #define LEN(X) strlen(X)
    #define F first
    #define S second
    using namespace std;
    const int N = 2e5 + 5;
    const double eps = 1e-7;
    const int mod = 1e9 + 7;
    typedef long long LL;
    typedef unsigned long long ULL;
    typedef long double LD;
    typedef pair<int, int> PII;
    typedef vector<int> VI;
    typedef vector<LL> VL;
    typedef vector<PII> VPII;
    typedef pair<LL, LL> PLL;
    typedef vector<PLL> VPLL;
    LL gcd(LL a, LL b) { return b > 0 ? gcd(b, a % b) : a; }
    LL ksm(LL a, LL b)
    {
        LL ans = 1;
        while (b)
        {
            if (b & 1)
                ans = ans * a % mod;
            a = a * a % mod;
            b >>= 1;
        }
        return ans % mod;
    }
    char s[N];
    map<int, int> mp;
    int main()
    {
        scanf("%s", s + 1);
        int n = strlen(s + 1);
        for (int i = 1; i <= n;)
        {
            if (s[i] == 'R')
            {
                int l = 0;
                while (i <= n && (s[i] == 'R'))
                {
                    i++;
                    l++;
                }
                int posl = i - 1;
                int posr = i;
                int r = 0;
                while (i <= n && (s[i] == 'L'))
                {
                    i++;
                    r++;
                }
                int sum = l + r;
                {
                    if (sum % 2 == 0)
                    {
                        mp[posl] = sum / 2;
                        mp[posr] = sum / 2;
                    }
                    else
                    {
                        int x = min(l, r);
                        int lx = l;
                        int rx = r;
                        l = sum / 2;
                        r = sum / 2 + 1;
                        if (lx < rx)
                        {
                            if (x % 2)
                            {
                                mp[posl] = r;
                                mp[posr] = l;
                            }
                            else
                            {
                                mp[posl] = l;
                                mp[posr] = r;
                            }
                        }
                        else
                        {
                            if (x % 2)
                            {
                                mp[posl] = l;
                                mp[posr] = r;
                            }
                            else
                            {
                                mp[posl] = r;
                                mp[posr] = l;
                            }
                        }
                    }
                }
            }
        }
        for (int i = 1; i <= n; i++)
        {
            if (mp[i])
                cout << mp[i] << ' ';
            else
                cout << 0 << ' ';
        }
        cout << endl;
        return 0;
    }
    
    
  • 相关阅读:
    tp5 查询问题 字段自增 字段比较
    七牛云 {"error":"no such domain"}
    mac 命令
    跟微信公众号一起来学api安全
    vue 运行别人项目
    php sha1withrsa
    thinkphp5 使用路由下分页 form表单 搜索
    P2134 百日旅行 (斜率优化,DP)
    [USACO Section 4.4]追查坏牛奶Pollutant Control (最小割)
    [HAOI2007] 理想的正方形 (单调队列)
  • 原文地址:https://www.cnblogs.com/strategist-614/p/12652622.html
Copyright © 2020-2023  润新知