1 条题解

  • 0
    @ 1991-6-19 8:42:47

    练33.1 3721数

    解题思路

    枚举 1~200,同时检查模 3 为 2 与模 7 为 1,符合则按升序输出。

    正确性说明

    按上述推导执行:每次仅处理当前输入或当前步骤,并把它对答案的贡献计入对应状态。所有需要处理的情况均被覆盖,结束时保存的量就是题目所求。

    易错点

    两个条件必须同时成立。

    复杂度

    固定200候选,时间 O(1),空间 O(1)。

    参考代码(C++11)

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        bool first = true;
        for (int i = 1; i <= 200; i++)
            if (i % 3 == 2 && i % 7 == 1) {
                if (!first)
                    cout << " ";
                cout << i;
                first = false;
            }
        cout << "\n";
        return 0;
    }
    
    • 1

    信息

    ID
    230
    时间
    1000ms
    内存
    64MiB
    难度
    入门
    标签
    递交数
    0
    已通过
    0
    上传者