AcWing
  • 首页
  • 课程
  • 题库
  • 更多
    • 竞赛
    • 题解
    • 分享
    • 问答
    • 应用
    • 校园
  • 关闭
    历史记录
    清除记录
    猜你想搜
    AcWing热点
  • App
  • 登录/注册

875-23 Pro

作者: 作者的头像   3include ,  2024-12-04 10:41:14 ,  所有人可见 ,  阅读 1


0


T1:

#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;

const int N = 100010;

struct teacher
{
    int years;
    bool operator < (const teacher & t) const {
        return years < t.years;
    }
}tea[N];

int main()
{
    int n;
    cin >> n;

    unordered_map<int, int> cnt;
    unordered_map<int, bool> printed;

    for (int i = 0; i < n ; i ++ ) {
        cin >> tea[i].years;
        cnt[tea[i].years] ++;
    }

    stable_sort(tea, tea + n);

    for (int i = 0; i < n ; i ++ ) {
        if (!printed[tea[i].years]) {
            cout << tea[i].years << " : " << cnt[tea[i].years] << endl;
            printed[tea[i].years] = true;
        }
    }

}

T2:

#include <iostream>

using namespace std;

const int N = 1010, M = 1010;

int f[N][M];
int n, m, q;

int cnt(int x1, int y1, int x2, int y2) 
{
    int res = 0;
    for (int i = x1; i <= x2; i ++ )
        for (int j = y1; j <= y2; j ++ ) {
            res += f[i][j];
        }
        return res;
}

int main()
{
    cin >> n >> m >> q;

    for (int i = 1; i <= n ; i ++ )
        for (int j = 1; j <= m ; j ++) 
            cin >> f[i][j];

    while (q -- ) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        cout << cnt(x1, y1, x2, y2) << endl;
    }

    return 0;
}

T3:

#include <iostream>

using namespace std;

const int N = 35;

int f[N];

int main()
{
    int n;
    cin >> n;

    f[1] = 1, f[2] = 2;

    /*对于n>2的情况,考虑最后一步的走法。
    如果最后一步是走了一级台阶到达第n级,那么前面n - 1级台阶的走法方案数为f(n - 1)种;
    如果最后一步是走了两级台阶到达第n级,那么前面n-2级台阶的走法方案数为f(n - 2)种。
    所以走到第n级台阶的总方案数f(n)=f(n - 1)+f(n - 2),这正好符合斐波那契数列的递推公式。*/
    for (int i = 3; i <= n; i ++ )
        f[i] = f[i-1] + f[i-2];

    cout << f[n] << endl;

    return 0;
}

0 评论

App 内打开
你确定删除吗?
1024
x

© 2018-2025 AcWing 版权所有  |  京ICP备2021015969号-2
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息