Practice.
A. Extremely Round
题意
给定一个整数 
思路
显然,对于 
时间复杂度:
对应AC代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t --){
        int n;
        cin >> n;
        int a = n, tot = 0;
        while(a >= 10) a /= 10, tot ++;
        cout << tot * 9 + a << '\n';
    }
    return 0;
}简单打卡题
B. Notepad#
题意
给定一个长为 
思路
我们不妨只寻找长为 
此处我们需要排除如下情况:
时间复杂度:
对应AC代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 30;
int a[N][N];
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t --){
        int n;
        cin >> n;
        string cur;
        cin >> cur;
        cur = ' ' + cur;
        memset(a, 0, sizeof a);
        bool ok = false;
        for(int i=1;i<n;i++){
            int o1 = cur[i] - 'a', o2 = cur[i + 1] - 'a';
            if(a[o1][o2] != 0 && a[o1][o2] != i - 1) {
                ok = true;
                break;
            }
            if(a[o1][o2] == 0) a[o1][o2] = i;
        }
        cout << (ok ? "YES" : "NO") << '\n';
    }
    return 0;
}WA了好几遍捏
C. Hamiltonian Wall
题意
给定一个长为 
思路
我们可以直接模拟,判断前者的入口在何处,若出现冲突就直接输出 
具体按照下面的方法模拟:
- 找出第一个不是 的列; 
- 将入口更新为 出现的位置; 
- 若相邻出现 或 ,输出 ; 
- 若出现多个 ,根据奇偶性判断之后的入口; 
- 遇到 直接输出 。 
- 无冲突输出 。 
时间复杂度:
对应AC代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
bool a[N];
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t, n;
    char c;
    cin >> t;
    while(t --){
        cin >> n;
        for(int i=0;i<n;i++){
            cin >> c;
            a[i] = c == 'B';
        }
        bool f = false, ans = true;
        int pre;
        cin >> c;
        if(a[0] && c == 'B') pre = 2, f = true;
        else if(a[0]) pre = 0;
        else if(c == 'B') pre = 1;
        else pre = -1;
        for(int i=1;i<n;i++){
            cin >> c;
            if(!ans) continue;
            int now;
            if(a[i] && c == 'B') now = 2;
            else if(a[i]) now = 0;
            else if(c == 'B') now = 1;
            else now = -1;
            if(f && now == 2) continue;
            f = false;
            if((pre == -1 && now != -1) || (pre == 0 && now == 1) || (pre == 1 && now == 0)){
                ans = false;
                continue;
            }
            if(now == 2) now = 1 - pre;
            pre = now;
        }
        cout << (ans ? "YES" : "NO") << '\n';
    }
    return 0;
}太模拟了,不过貌似一笔画不止可以暴力模拟(
- 本文链接 https://floating-ocean.github.io/blog_old/posts/1807504053/
- 版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!