PTA题解 --- 静静的推荐(C语言)

今天是PTA题库解法讲解的第七天,今天我们要讲解静静的推荐,题目如下:

解题思路:

这个问题的核心在于如何在满足给定条件的情况下,最大化推荐学生的数量。首先,我们需要过滤出所有天梯赛成绩不低于175分的学生。然后,我们要按天梯赛成绩排序,如果天梯赛成绩相同,再根据PAT成绩排序。在推荐学生时,我们需要按批次进行,确保每一批的成绩严格递增,同时如果同一天梯赛成绩的学生PAT成绩达到了企业的面试分数线,也可以被接受。

代码实现:

复制代码
#include <stdio.h>
#include <stdlib.h>

typedef struct {
    int ladderScore;
    int patScore;
} Student;

int compareStudents(const void *a, const void *b) {
    Student *studentA = (Student *)a;
    Student *studentB = (Student *)b;
    if (studentA->ladderScore == studentB->ladderScore) {
        return studentB->patScore - studentA->patScore; // Descending PAT scores
    }
    return studentA->ladderScore - studentB->ladderScore; // Ascending Ladder scores
}

int main() {
    int N, K, S;
    scanf("%d %d %d", &N, &K, &S);
    Student students[N];
    int validStudents = 0;

    for(int i = 0; i < N; i++) {
        scanf("%d %d", &students[i].ladderScore, &students[i].patScore);
        if (students[i].ladderScore >= 175) {
            validStudents++;
        } else {
            students[i].ladderScore = -1; // Mark invalid students
        }
    }

    // Sort students based on Ladder and PAT scores
    qsort(students, N, sizeof(Student), compareStudents);

    // Logic to count recommended students goes here.
    // This is a simplified placeholder for the complex logic required.
    // You'll need to implement the detailed selection criteria as described.

    printf("%d\n", validStudents); // Placeholder for actual count of recommended students
    return 0;
}

提交结果:

本题部分没有通过,小伙伴们可以在评论区讨论,来个最优解哦~

相关推荐
Ada's42 分钟前
【计算机基础系列】003:Python数据结构
开发语言·数据结构·python
2601_962885721 小时前
如何用 Python 计算 TRIX 三重指数平滑均线指标?
开发语言·python
还卿一钵无情泪2 小时前
Unsloth 微调 构建自己的大模型 没有GPU也能微调
linux·开发语言·人工智能·python·大模型·nlp·unsloth
倔强的石头1063 小时前
应用账号最小权限实践:读写账号、报表账号、运维账号分层
java·运维·开发语言
传人once3 小时前
页面中心圆圈放大效果如何写
开发语言·javascript·ecmascript
NeilYuen3 小时前
【C++】STL源码仿写(二):vector
开发语言·c++
蜗牛互联网4 小时前
Python消费Responses SSE事件:增量文本、超时与取消
java·开发语言·人工智能·后端·python
weixin_307779134 小时前
C++代码实现MATLAB中的crossval函数功能
开发语言·c++·算法·matlab
ttwuai5 小时前
Go后台管理系统开源项目:4个官方仓库怎么追溯和核验
开发语言·golang·开源
谢亮_vipxieliang5 小时前
Go Worker Pool 设计——从原理到生产级实现
开发语言·后端·golang