Codeforces Round 806 (Div. 4)

简介: Codeforces Round 806 (Div. 4)A~G

A. YES or YES?

给一个字符串,看它是不是YES

把小写字母转换成大写字母,在判断是不是YES

#include<bits/stdc++.h>
using namespace std;

void solve()
{
    string str;
    cin >> str;
    for(int i = 0; i < 3; i ++ )
    {
        if(str[i] < 'z' && str[i] > 'a')
            str[i] -= 32;
    }
    cout << (str == "YES" ? "YES" : "NO") << endl;
}

int main()
{
    freopen("test.in", "r", stdin);
    int tt;
    cin >> tt;
    while(tt -- )
    {
        solve();
    }
}

B. ICPC Balloons

给一个字符串,遍历,如果是第一个出现的字母,就+2,否则 + 1
#include<bits/stdc++.h>
using namespace std;

void solve()
{
    int n;
    string s;
    cin >> n >> s;
    int point = 0;
    unordered_map<char, int> mp;
    for(auto c : s)
    {
        if(mp[c] == 0)
            point += 2;
        else
            point += 1;
        mp[c] ++ ;
    }
    cout << point << endl;
}

int main()
{
    freopen("test.in", "r", stdin);
    int tt;
    cin >> tt;
    while(tt -- )
    {
        solve();
    }
    return 0;
}

C. Cypher

模拟倒着回去
#include<bits/stdc++.h>
using namespace std;
int a[110];
void solve()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i ++ ) cin >> a[i];
    for(int i = 0; i < n; i ++ )
    {
        int x;
        string str;
        cin >> x >> str;
        int res = a[i];
        for(int j = 0; j < x; j ++ )
        {
            if(str[j] == 'D') res = (res + 1) % 10;
            else res = (res - 1 + 10) % 10;
        }
        cout << res << " ";
    }
    cout << "\n";
}

int main()
{
    freopen("test.in", "r", stdin);
    int tt;
    cin >> tt;
    while(tt -- )
    {
        solve();
    }
    return 0;
}

D. Double Strings

先把所有字符串存到set中,在对每个字符串,枚举它断开的位置,因为字符串数量较多,但长度最多为8,查看字符串分开的前后字符串是否都存在,如果都存在,就输出1,否则输出0
#include<bits/stdc++.h>
using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<string> s(n);
    for(int i = 0; i < n; i ++ )
        cin >> s[i];

    set<string> se;
    for(int i = 0; i < n; i ++ )
        se.insert(s[i]);
    
    string ans;
    for(int i = 0; i < n; i ++ )
    {
        bool f = false;
        int x = s[i].size();
        for(int j = 1; j < x; j ++ )
        {
            if(se.count(s[i].substr(0, j)) == 1 && se.count(s[i].substr(j)) == 1)
                f = true;
        }
        if(f) ans += "1";
        else ans += "0";
    }
    cout << ans << endl;
}

int main()
{
    freopen("test.in", "r", stdin);
    int tt;
    cin >> tt;
    while(tt -- )
    {
        solve();
    }
    return 0;
}

E. Mirror Grid

经过旋转,每个位置都有自己联系的位置,对于每个联系,统计这几个位置的0的个数跟1的个数,答案累加上最小的数,并将这几个位置置为true,不在统计
#include<bits/stdc++.h>
using namespace std;

char g[110][110];
bool st[110][110];

void solve()
{
    memset(st, 0, sizeof st);
    int n;
    cin >> n;
    for(int i = 0; i < n; i ++ )
        for(int j = 0; j < n; j ++ )
            cin >> g[i][j];
    
    int res = 0;
    for(int i = 0; i < n; i ++ )
        for(int j = 0; j < n; j ++ )
        {
            if(st[i][j]) continue;
            int cnt0 = 0, cnt1 = 0;
            if(g[i][j] == '1') cnt1 ++ ;
            else cnt0 ++ ;
            if(g[j][n - i - 1] == '1') cnt1 ++ ;
            else cnt0 ++ ;
            if(g[n - i - 1][n - j - 1]== '1') cnt1 ++ ;
            else cnt0 ++ ;
            if(g[n - j - 1][i] == '1') cnt1 ++ ;
            else cnt0 ++ ;

            res += min(cnt0, cnt1);

            st[i][j] = true;
            st[j][n - i - 1] = true;
            st[n - i - 1][n - j - 1] = true;
            st[n - j - 1][i] = true;
        }
    cout << res << endl;
}

int main()
{
    freopen("test.in", "r", stdin);
    int tt;
    cin >> tt;
    while(tt -- )
    {
        solve();
    }
    return 0;
}

F. Yet Another Problem About Pairs Satisfying an Inequality

计算索引对的数量,使得ai < i < aj < j,先统计都哪个 ai < i,然后前缀和,对于每一个成立的,答案累加前面所有的数量 p[a[i] - 1],因为 i < a[j]
#include <bits/stdc++.h>
using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i];

    vector<int> cnt(n + 1);
    for (int i = 1; i <= n; i++)
        cnt[i] = (i > a[i]);

    vector<int> p(n + 1);
    for (int i = 1; i <= n; i++)
        p[i] = p[i - 1] + cnt[i];

    long long ans = 0;
    for (int i = 1; i <= n; i++)
        if (1 < a[i] && cnt[i])
            ans += p[a[i] - 1];

    cout << ans << endl;
}

int main()
{
    freopen("test.in", "r", stdin);
    int tt;
    cin >> tt;
    while (tt--)
    {
        solve();
    }
    return 0;
}

G. Good Key, Bad Key

如果用好钥匙的个数是固定的,那么把钥匙都放到最前面开是最优解

所以就枚举到底用几把好钥匙,然后更新答案

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[100010], s[100010];
void solve()
{
    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= n; i ++ )
    {
        cin >> a[i];
        s[i] = s[i - 1] + a[i] - k;
    }
    ll res = 0;
    for(int i = 0; i <= n; i ++ )
    {
        ll now = s[i];
        for(int j = i + 1; j <= min(n, i + 31); j ++ )
            now += a[j] >> (j - i);
        
        res = max(res, now);
    }
    cout << res << endl;
}

int main()
{
    freopen("test.in", "r", stdin);
    int _t;
    cin >> _t;
    while(_t--)
    {
        solve();
    }
    return 0;
}
目录
相关文章
|
人工智能 算法 BI
Codeforces Round 891 (Div. 3)
Codeforces Round 891 (Div. 3)
129 0
Codeforces Round 891 (Div. 3)
Codeforces Round #192 (Div. 2) (329A)C.Purification
Codeforces Round #192 (Div. 2) (329A)C.Purification
48 0
Codeforces Round #186 (Div. 2)A、B、C、D、E
Ilya得到了一个礼物,可以在删掉银行账户最后和倒数第二位的数字(账户有可能是负的),也可以不做任何处理。
45 0
Codeforces Round #178 (Div. 2)
在n条电线上有不同数量的鸟, Shaass开了m枪,每一枪打的是第xi条电线上的第yi只鸟,然后被打中的这只鸟左边的飞到第i-1条电线上,右边的飞到i+1条电线上,没有落脚点的鸟会飞走。
55 0
Codeforces Round #742 (Div. 2)
Codeforces Round #742 (Div. 2)
52 0
|
人工智能 BI
Codeforces Round 827 (Div. 4)
Codeforces Round 827 (Div. 4)A~G题解
106 0
Codeforces Round #644 (Div. 3)(A~G)
Codeforces Round #644 (Div. 3)(A~G)
125 0
Codeforces Round #723 (Div. 2)B. I Hate 1111
Description You are given an integer x. Can you make x by summing up some number of 11,111,1111,11111,…? (You can use any number among them any number of times). For instance, 33=11+11+11 144=111+11+11+11
188 0
Codeforces Round #723 (Div. 2)B. I Hate 1111