传送门

A Telephone Number standard

找到第一个8所在的位置即可,最后判断一下,如果没有找到或者第一个8所在的位置后面的数不够11个就不行

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define met_x(a) memset(a,0x3f,sizeof a)
#define mpy(a,b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define fi first
#define se second
#define PII pair<int,int>
#define PDD pair<double,double>
#define PCI pair<char,int>
#define endl '\n'
const int N = 10010;
const int M = 110;
const int MOD = 998244353;
const int EPS = 1e-8;
const int INF = 0x3f3f3f3f;

using namespace  std;


void solve() {
    int n;
    string s;
    cin >> n >> s;
    int pos = -1;
    for (int i = 0; i < n; i++) {
        if (s[i] == '8') {
            pos = i;
            break;
        }
    }
    if (n - pos >= 11 && pos != -1)cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main() {
    IOS;
    int h_h = 1;
    cin >> h_h;
    while (h_h--)solve();
    return 0;
}

B Lost Numbers standard

这是一道交互题,首先要熟悉输入输出的顺序,先输出,也就是查询,读入交互机返回的结果,根据返回的结果来推测结果,记得清空缓冲区。这个题我们可以把相邻的前五个数的乘积求出来,然后用全排列的函数暴力的去判断即可。

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define met_x(a) memset(a,0x3f,sizeof a)
#define mpy(a,b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define fi first
#define se second
#define PII pair<int,int>
#define PDD pair<double,double>
#define PCI pair<char,int>
//#define endl '\n'
const int N = 500010;
const int M = 110;
const int MOD = 998244353;
const int EPS = 1e-8;
const int INF = 0x3f3f3f3f;

using namespace  std;

void solve() {
    int ans[7] = {0, 4, 8, 15, 16, 23, 42};
    int a, b, c, d;
    cout << "? 1 2" << endl;
    fflush(stdout);
    cin >> a;
    cout << "? 2 3" << endl;
    fflush(stdout);
    cin >> b;
    cout << "? 3 4" << endl;
    fflush(stdout);
    cin >> c;
    cout << "? 4 5" << endl;
    fflush(stdout);
    cin >> d;
    do {
        if (ans[1] * ans[2] == a && ans[2] * ans[3] == b && ans[3] * ans[4] == c && ans[4] * ans[5] == d) {
            break;
        }
    } while (next_permutation(ans + 1, ans + 7));
    cout << "! ";
    for (int i = 1; i <= 6; i++)cout << ans[i] << ' ';
    fflush(stdout);
}

int main() {
    IOS;
    int h_h = 1;
    //cin >> h_h;
    while (h_h--)solve();
    return 0;
}

C News Distribution standard

并查集的题,还要额外去维护每个集合的元素有多少个,最后输出即可,也可以建图跑DFS对于每个点计算出和它相连的点有多少,输出即可。

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define met_x(a) memset(a,0x3f,sizeof a)
#define mpy(a,b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define fi first
#define se second
#define PII pair<int,int>
#define PDD pair<double,double>
#define PCI pair<char,int>
#define endl '\n'
const int N = 500010;
const int M = 110;
const int MOD = 998244353;
const int EPS = 1e-8;
const int INF = 0x3f3f3f3f;

using namespace  std;

int fa[N],s[N];
int n,m ;

int find(int x) {
    if (fa[x] != x)fa[x] = find(fa[x]);
    return fa[x];
}

void solve() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++)fa[i] = i, s[i] = 1;
    while (m--) {
        int k;
        cin >> k;
        vector<int> aa(k);
        for (auto &i: aa)cin >> i;
        for (int i = 0; i < k - 1; i++) {
            int pa = find(aa[i]);
            int pb = find(aa[i + 1]);
            if (pa != pb)fa[pa] = pb, s[pb] += s[pa];
        }
    }
    for (int i = 1; i <= n; i++)cout << s[find(i)] << ' ';
}

int main() {
    IOS;
    int h_h = 1;
    //cin >> h_h;
    while (h_h--)solve();
    return 0;
}

D Bicolored RBS

从左往右边遍历一遍,遇到一个左括号,就用最近的一个右括号与他匹配进行染色,交替进行染色就可以了,因为要保证深度经可能的小

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
#define met_0(a) memset(a,0,sizeof a)
#define met_1(a) memset(a,-1,sizeof a)
#define met_x(a) memset(a,0x3f,sizeof a)
#define mpy(a,b) memcopy(a,sizeof b,b)
#define ll long long
#define ld long double
#define ull unsigned long long
#define fi first
#define se second
#define PII pair<int,int>
#define PDD pair<double,double>
#define PCI pair<char,int>
#define endl '\n'
const int N = 500010;
const int M = 110;
const int MOD = 998244353;
const int EPS = 1e-8;
const int INF = 0x3f3f3f3f;

using namespace  std;

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    string ans = s;
    map<char, int> pos;
    vector<int > right;
    for (int i = 0; i < n; i++) {
        pos[s[i]] = i;
        if (s[i] == ')')right.push_back(i);
    }
    reverse(right.begin(), right.end());
    bool ok = true;
    //for(auto i:right)cout<<i<<' ';
    for (int i = 0; i < n; i++) {
        if (s[i] == '(') {
            //cout<<i<<endl;
            if (ok) {
                ok = false;
                ans[i] = '0';
                ans[right.back()] = '0';
                right.pop_back();
            } else {
                ok = true;
                ans[i] = '1';
                ans[right.back()] = '1';
                right.pop_back();
            }
        }
    }
    cout << ans << endl;
}

int main() {
    IOS;
    int h_h = 1;
    //cin >> h_h;
    while (h_h--)solve();
    return 0;
}