社团测试题解

签到题

简单排序,对数组排序后直接输出第k个数即可,这里选择使用sort库函数来进行排序求解,可以自行选择别的方式进行求解。

#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
const int N = 1e5 + 10;
int a[N];
int main(void)
{
    int n,k;
    cin >> n >> k;
    for(int i = 0 ; i < n ; i ++)
        cin >> a[i];
    sort(a, a+n);
    cout << a[k -1 ] <<endl;
    return 0;
}

晨拥的魔法

模拟即可,乍一看题目很哄人,实则只用循环m次,每次遍历所有的随从怪物,如果恰好消灭则让伤害值+1,别的情况直接求解即可。

#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
const int N = 1e5 + 10;
int a[N];
int main(void)
{
    int x = 2; // 初始伤害
    int res = 0;
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    while (m--)
    {
        for (int i = 0; i < n; i++)
        {
            if (a[i] == x)
            {
                a[i] = -1;
                x++;
            }
            else if (a[i] < x)
                a[i] = -1;
            else
                a[i] -= x;
        }
        res += x;
    }
    cout << res << endl;
    return 0;
}

全部评论

相关推荐

07-11 10:56
门头沟学院 Java
码客明:大胆的说自己能实习6个月就行
点赞 评论 收藏
分享
asdasdasda...:19岁,不容易啊可能升个本会好点,现在学历歧视太严重了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务