1 条题解

  • 0
    @ 2024-4-12 11:18:58

    暴力枚举即可

    先看题,要求是要2023年的日期,先扫一扫能组成2023的最小长度为4的序列,这个序列就用来构造年份。很明显,只需要枚举后四个数字组成的序列是否日期合法就行了。扫一眼下来,我们只需要枚举8,5,1,6,3,4,6,7,0,7,8,2,7,6,8,9,5,6,5,6,1,4,0,1,0,0,9,4,8,0,9,1,2,8,5,0,2,5,3,3段即可。

    参考代码

    #include <bits/stdc++.h>
    using namespace std;
    using i64 = long long;
    signed main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        unordered_set<i64> s;
        const int a[]{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        vector<i64> arr{8,5,1,6,3,4,6,7,0,7,8,2,7,6,8,9,5,6,5,6,1,4,0,1,0,0,9,4,8,0,9,1,2,8,5,0,2,5,3,3};
        int n = arr.size(), ans{};
        for(int i1 = 0; i1 < n - 3; ++i1)
            for(int i2 = i1 + 1; i2 < n - 2; ++i2)
                for(int i3 = i2 + 1; i3 < n - 1; ++i3)
                    for(int i4 = i3 + 1; i4 < n; ++i4) {
                        int mouth = arr[i1] * 10 + arr[i2];
                        int day = arr[i3] * 10 + arr[i4];
                        if(mouth > 12 or mouth <= 0 or day > a[mouth] or day <= 0)
                            continue;
                        s.emplace(mouth * 100 + day);
                    }
        cout << s.size();
    
        return 0;
    }
    
    • 1

    信息

    ID
    1001
    时间
    1000ms
    内存
    256MiB
    难度
    3
    标签
    递交数
    32
    已通过
    15
    上传者