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;
}

原文链接: https://www.cnblogs.com/strategist-614/p/12652622.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    ABC136

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/340623

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年3月2日 上午12:41
下一篇 2023年3月2日 上午12:41

相关推荐