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

23-真题

作者: 作者的头像   把头发掀起来看世界 ,  2024-11-23 17:08:56 ,  所有人可见 ,  阅读 1


0


1.工龄排序

#include <iostream>
#include <algorithm>
using namespace std;

const int N=51;
int age[N],n;

int main()
{
    cin>>n;
    while(n--)
    {
        int a;
        cin>>a;
        age[a]++;
    }
    for(int i=0;i<51;i++)
    {
        if(age[i]==0) continue;
        printf("%d : %d\n",i,age[i]);
    }
    return 0;
}

/*
8
10 2 0 5 7 2 5 2
*/

2.二维前缀和

#include <iostream>
using namespace std;

const int N=1010;
int a[N][N];
int n,m,q;

int main()
{
    cin>>n>>m>>q;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>a[i][j];

    while(q--)
    {
        int x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
        if(x1>x2)swap(x1,x2);
        if(y1>y2)swap(y1,y2);

        int sum=0;
        for(int i=x1;i<=x2;i++)
        {
            for(int j=y1;j<=y2;j++)
            {
                sum+=a[i][j];
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}


/*
3 4 3
1 7 2 4
3 6 2 8
2 1 2 3
1 1 2 2
2 1 3 4
1 3 3 4
*/

3.机器人跳格子

#include <iostream>
using namespace std;

const int N=40;
int f[N];
int main()
{
    int n;
    cin>>n;

    f[1]=1,f[2]=2;
    for(int i=3;i<=n;i++)
    {
        f[i]=f[i-1]+f[i-2];
    }
    cout<<f[n];
    return 0;
}

0 评论

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

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