Codeforces Round #785 (Div. 2)

Posted 最爱小崔同学

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #785 (Div. 2)相关的知识,希望对你有一定的参考价值。

A. Subtle Substring Subtraction

A题就是 a~z分别有权值 1~26吧然后就是由于每个人都是选让自己分数最高的很明显如果n为偶数

就是全拿去,另一种就是奇数情况这种特殊看一下1但是其实也不用 第一个人取得数字个数就是

n-1是吧。然后判断是从头取n-1个还是从尾部取n-1个。。。

#pragma GCC optimize(2)

#pragma GCC optimize(3)

#pragma GCC optimize(fast)

#include<iostream>

#include<algorithm>

#include<vector>

#include<queue>

#include<map>

#include<unordered_map>

#include<cstring>

#include<cstdio>

#include<string>

#include<assert.h>

#include<cmath>

#include<array>

using namespace std;

#define pb push_back

#define endl '\\n'

#define debug(x) cout<<"#x"<<" "<<x<<endl

#define _for(i, a, b) for (int i = (a); i < (b);i++)

#define _rep(i, a, b) for (int i = (a); i <= (b);i++)

using ll = long long;

using pii = pair<int, int>;

template <typename T>

inline void read(T &f)

    f=1;T x=0;char ch=getchar();while(ch<'0'||ch>'9')if(ch=='-')f=-1;ch=getchar(); while(ch>='0'&&ch<='9')x=x*10+ch-'0';ch=getchar();f*=x;

template <typename T>

inline void print(T x)

    if(x<0)putchar('-');x=-x;if(x>9)print(x/10);putchar(x%10+'0');

template<int MOD, int RT> struct Mint

    int val;

    static const int mod = MOD;

    Mint(ll v = 0) val = int(-mod < v && v < mod? v: v % mod); if (val < 0) val += mod;

    inline friend bool operator == (const Mint& a, const Mint& b) return a.val == b.val;

    inline friend bool operator != (const Mint& a, const Mint& b) return !(a == b);

    inline friend bool operator < (const Mint& a, const Mint& b) return a.val < b.val;

    inline friend bool operator > (const Mint& a, const Mint& b) return a.val > b.val;

    inline friend bool operator <= (const Mint& a, const Mint& b) return a.val <= b.val;

    inline friend bool operator >= (const Mint& a, const Mint& b) return a.val >= b.val;

    inline Mint& operator += (const Mint& rhs) return (*this) = Mint((*this).val + rhs.val);

    inline Mint& operator -= (const Mint& rhs) return (*this) = Mint((*this).val - rhs.val);

    inline Mint& operator *= (const Mint& rhs) return (*this) = Mint(1ll * (this->val) * rhs.val);

    inline Mint operator - () const return Mint(-val);

    inline Mint& operator ++ () return (*this) = (*this) + 1;

    inline Mint& operator -- () return (*this) = (*this) - 1;

    inline friend Mint operator + (Mint a, const Mint& b) return a += b;

    inline friend Mint operator - (Mint a, const Mint& b) return a -= b;

    inline friend Mint operator * (Mint a, const Mint& b) return a *= b;

    inline friend Mint qkpow(Mint a, ll n)

        assert(n >= 0); Mint ret = 1;

        for (; n; n >>= 1, a *= a) if (n & 1) ret *= a;

        return ret;

   

    inline friend Mint inverse(Mint a) assert(a != 0); return qkpow(a, mod- 2 );

;

using mint = Mint<998244353, 5>;

template<class _A, class _B> ll fpow(_A A, _B B, ll mod=1e18) ll _r=1; for (;B;B >>= 1, A=(A*A)%mod) if (B&1) _r=(_r*A)%mod; return _r; ;

void  solve()

    string a;

    cin >> a;

    int ans = 0;

    if(a.size()%2==0)  

        for(auto x:a)

            ans += x - 'a' + 1;

       

        cout << "Alice " << ans << endl;

   

    else

        int res1 = 0;

        int res2 = 0;

        for (int i = 0; i < a.size()-1;i++)

            res1 += a[i] - 'a' + 1;

       

        for (int i = a.size() - 1; i >= 1;i--)

            res2 += a[i] - 'a' + 1;

        if(res1>res2)

       

            int cnt = res1 - (a.back() - 'a' + 1);

            if(cnt>0)

                cout << "Alice " << cnt << endl;

           

            else

                cout << "Bob " << -cnt << endl;

       

        else

            int cnt = res2 - (a[0] - 'a' + 1);

            if(cnt>0)

                cout << "Alice " << cnt << endl;

           

            else

                cout << "Bob " << -cnt << endl;

       

   

    return;

int main()

    cin.tie(nullptr)->sync_with_stdio(false);

    int _;

    cin >> _;

    while(_--)

   

        solve();

   

    return 0;

第二题

B. A Perfectly Balanced String? 

就是枚举每个字母,然后看 , 不含有这个字母的子串有无大于数量大于2的 下面就可用双指针了枚举就好了i就是双指针区间的左端点,j就是双指针区间的 右端点 

#pragma GCC optimize(2)

#pragma GCC optimize(3)

#pragma GCC optimize(fast)

#include<iostream>

#include<algorithm>

#include<vector>

#include<queue>

#include<map>

#include<unordered_map>

#include<cstring>

#include<cstdio>

#include<string>

#include<assert.h>

#include<cmath>

#include<array>

using namespace std;

#define pb push_back

#define endl '\\n'

#define debug(x) cout<<"#x"<<" "<<x<<endl

#define _for(i, a, b) for (int i = (a); i < (b);i++)

#define _rep(i, a, b) for (int i = (a); i <= (b);i++)

using ll = long long;

using pii = pair<int, int>;

template <typename T>

inline void read(T &f)

    f=1;T x=0;char ch=getchar();while(ch<'0'||ch>'9')if(ch=='-')f=-1;ch=getchar(); while(ch>='0'&&ch<='9')x=x*10+ch-'0';ch=getchar();f*=x;

template <typename T>

inline void print(T x)

    if(x<0)putchar('-');x=-x;if(x>9)print(x/10);putchar(x%10+'0');

template<int MOD, int RT> struct Mint

    int val;

    static const int mod = MOD;

    Mint(ll v = 0) val = int(-mod < v && v < mod? v: v % mod); if (val < 0) val += mod;

    inline friend bool operator == (const Mint& a, const Mint& b) return a.val == b.val;

    inline friend bool operator != (const Mint& a, const Mint& b) return !(a == b);

    inline friend bool operator < (const Mint& a, const Mint& b) return a.val < b.val;

    inline friend bool operator > (const Mint& a, const Mint& b) return a.val > b.val;

    inline friend bool operator <= (const Mint& a, const Mint& b) return a.val <= b.val;

    inline friend bool operator >= (const Mint& a, const Mint& b) return a.val >= b.val;

    inline Mint& operator += (const Mint& rhs) return (*this) = Mint((*this).val + rhs.val);

    inline Mint& operator -= (const Mint& rhs) return (*this) = Mint((*this).val - rhs.val);

    inline Mint& operator *= (const Mint& rhs) return (*this) = Mint(1ll * (this->val) * rhs.val);

    inline Mint operator - () const return Mint(-val);

    inline Mint& operator ++ () return (*this) = (*this) + 1;

    inline Mint& operator -- () return (*this) = (*this) - 1;

    inline friend Mint operator + (Mint a, const Mint& b) return a += b;

    inline friend Mint operator - (Mint a, const Mint& b) return a -= b;

    inline friend Mint operator * (Mint a, const Mint& b) return a *= b;

    inline friend Mint qkpow(Mint a, ll n)

        assert(n >= 0); Mint ret = 1;

        for (; n; n >>= 1, a *= a) if (n & 1) ret *= a;

        return ret;

   

    inline friend Mint inverse(Mint a) assert(a != 0); return qkpow(a, mod- 2 );

;

using mint = Mint<998244353, 5>;

template<class _A, class _B> ll fpow(_A A, _B B, ll mod=1e18) ll _r=1; for (;B;B >>= 1, A=(A*A)%mod) if (B&1) _r=(_r*A)%mod; return _r; ;

void  solve()

    string a;

    cin >> a;

    int ans = 0;

    if(a.size()%2==0)  

        for(auto x:a)

            ans += x - 'a' + 1;

       

        cout << "Alice " << ans << endl;

   

    else

        int res1 = 0;

        int res2 = 0;

        for (int i = 0; i < a.size()-1;i++)

            res1 += a[i] - 'a' + 1;

       

        for (int i = a.size() - 1; i >= 1;i--)

            res2 += a[i] - 'a' + 1;

        if(res1>res2)

       

            int cnt = res1 - (a.back() - 'a' + 1);

            if(cnt>0)

                cout << "Alice " << cnt << endl;

           

            else

                cout << "Bob " << -cnt << endl;

       

        else

            int cnt = res2 - (a[0] - 'a' + 1);

            if(cnt>0)

                cout << "Alice " << cnt << endl;

           

            else

                cout << "Bob " << -cnt << endl;

       

   

    return;

int main()

    cin.tie(nullptr)->sync_with_stdio(false);

    int _;

    cin >> _;

    while(_--)

   

        solve();

   

    return 0;

C. Palindrome Basis 

感觉C题不是很难。比B好像。。就是一个背包 

#pragma GCC optimize(2)

#pragma GCC optimize(3)

#pragma GCC optimize(fast)

#include<iostream>

#include<algorithm>

#include<vector>

#include<queue>

#include<map>

#include<unordered_map>

#include<cstring>

#include<cstdio>

#include<string>

#include<assert.h>

#include<cmath>

#include<array>

using namespace std;

#define pb push_back

#define endl '\\n'

#define debug(x) cout<<"#x"<<" "<<x<<endl

#define _for(i, a, b) for (int i = (a); i < (b);i++)

#define _rep(i, a, b) for (int i = (a); i <= (b);i++)

using ll = long long;

using pii = pair<int, int>;

template <typename T>

inline void read(T &f)

    f=1;T x=0;char ch=getchar();while(ch<'0'||ch>'9')if(ch=='-')f=-1;ch=getchar(); while(ch>='0'&&ch<='9')x=x*10+ch-'0';ch=getchar();f*=x;

template <typename T>

inline void print(T x)

    if(x<0)putchar('-');x=-x;if(x>9)print(x/10);putchar(x%10+'0');

template<int MOD, int RT> struct Mint

    int val;

    static const int mod = MOD;

    Mint(ll v = 0) val = int(-mod < v && v < mod? v: v % mod); if (val < 0) val += mod;

    inline friend bool operator == (const Mint& a, const Mint& b) return a.val == b.val;

    inline friend bool operator != (const Mint& a, const Mint& b) return !(a == b);

    inline friend bool operator < (const Mint& a, const Mint& b) return a.val < b.val;

    inline friend bool operator > (const Mint& a, const Mint& b) return a.val > b.val;

    inline friend bool operator <= (const Mint& a, const Mint& b) return a.val <= b.val;

    inline friend bool operator >= (const Mint& a, const Mint& b) return a.val >= b.val;

    inline Mint& operator += (const Mint& rhs) return (*this) = Mint((*this).val + rhs.val);

    inline Mint& operator -= (const Mint& rhs) return (*this) = Mint((*this).val - rhs.val);

    inline Mint& operator *= (const Mint& rhs) return (*this) = Mint(1ll * (this->val) * rhs.val);

    inline Mint operator - () const return Mint(-val);

    inline Mint& operator ++ () return (*this) = (*this) + 1;

    inline Mint& operator -- () return (*this) = (*this) - 1;

    inline friend Mint operator + (Mint a, const Mint& b) return a += b;

    inline friend Mint operator - (Mint a, const Mint& b) return a -= b;

    inline friend Mint operator * (Mint a, const Mint& b) return a *= b;

    inline friend Mint qkpow(Mint a, ll n)

        assert(n >= 0); Mint ret = 1;

        for (; n; n >>= 1, a *= a) if (n & 1) ret *= a;

        return ret;

   

    inline friend Mint inverse(Mint a) assert(a != 0); return qkpow(a, mod- 2 );

;

const int mod = 1e9 + 7;

using mint = Mint<mod, 5>;

template<class _A, class _B> ll fpow(_A A, _B B, ll mod=1e18) ll _r=1; for (;B;B >>= 1, A=(A*A)%mod) if (B&1) _r=(_r*A)%mod; return _r; ;

vector<int> f;

const int N = 4e4 + 100;

mint dp[N];

void solve()

    int n;

    cin >> n;

    cout << dp[n].val << endl;

bool check(int i)

    string a = to_string(i);

    int l = 0, r = a.size() - 1;

    while(l<r)

   

        if(a[l]!=a[r])

            return false;

        l++, r--;

   

    return true;

void innit()

    int n = 4e4 + 10;

    for (int i = 1; i <= n;i++)

        if(check(i))

            f.push_back(i);

    dp[0] = 1;

    for (int i = 0; i < f.size();i++)

        for (int j = 1; j <= 4e4 + 10;j++)

            if(j>=f[i])

                dp[j] += dp[j - f[i]];

   

int main()  

    cin.tie(nullptr)->sync_with_stdio(false);

    innit();

    int _;

    cin >> _;

    while(_--)

        solve();

    return 0;

//总计:b题做的太久了,思维能力不太好啊。差点掉打分。。第三题做了20分钟。。。幸好是小号D题应该推公式吧。没时间看了

以上是关于Codeforces Round #785 (Div. 2)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #785 (Div. 2)

Codeforces Round #785 (Div. 2)

Codeforces Round #436 E. Fire(背包dp+输出路径)

[ACM]Codeforces Round #534 (Div. 2)

Codeforces 785A

CodeForces - 785C