oj96

个人总结:利用结构体来存储每个学生的数据,再根据每个学生的情况来判断获取什么奖学金/

#include <stdio.h>
#include <string.h>
//定义存储学生信息的结构体
struct Student{
    char name[21];         //姓名,长度不超过20
    int finalScore;        //期末平均成绩
    int classScore;        //班级评议成绩
    char isLeader;         //是否是学生干部 (Y/N)
    char isWest;           //是否是西部省份学生 (Y/N)
    int papers;            //发表的论文数
};
int main(){
    int n;
    while(scanf("%d", &n) != EOF){
        struct Student students[n];
        int student_sum = 0, max = 0, j = -1;//student_sum记录所有人奖学金总数
        for(int i = 0; i < n; i++){
            int sum = 0;//记录每名学生获得的奖学金
            scanf("%s %d %d %c %c %d",
                  students[i].name,
                  &students[i].finalScore,
                  &students[i].classScore,
                  &students[i].isLeader,
                  &students[i].isWest,
                  &students[i].papers);
            if(students[i].finalScore > 80 && students[i].papers > 0){
                sum += 8000;
                student_sum += 8000;
            }
            if(students[i].finalScore > 85 && students[i].classScore > 80){
                sum += 4000;
                student_sum += 4000;
            }
            if(students[i].finalScore > 90){
                sum += 2000;
                student_sum += 2000;
            }
            if(students[i].finalScore > 85 && students[i].isWest == 'Y'){
                sum += 1000;
                student_sum += 1000;
            }
            if(students[i].classScore > 80 && students[i].isLeader == 'Y'){
                sum += 850;
                student_sum += 850;
            }
            if(sum > max){//找获得奖学金最多的学生
                max = sum;
                j = i;
            }
        }
        printf("%s\n%d\n%d\n\n", students[j].name, max, student_sum);
    }
    return 0;
}

OJ97

个人总结:

 isPalindrome() 函数判断一个数组是否回文,使用 arr[] 数组存储一个数的十进制数,arr1[] 数组存储该数的二进制数,随后用 isPalindrome() 函数判断这两个数组是否回文,若均回文输出Yes,否则输出No    
 

#include <stdio.h>
#include <string.h>
#define MAX_SIZE 99999
//判断数组(长度len)是否是回文
int isPalindrome(int str[], int len){
    for(int i = 0; i < len / 2; i++){
        if(str[i] != str[len - 1 - i])
            return 0;
    }
    return 1;
}
int main(){
    int n;
    while(scanf("%d", &n) != EOF){
        int arr[MAX_SIZE], arr1[MAX_SIZE];
        int temp = n, i = 0, j = 0;
        while(temp > 0){
            arr[i++] = temp % 10;
            temp /= 10;
        }
        temp = n;
        while(temp > 0){
            arr1[j++] = temp % 2;
            temp /= 2;
        }
        if(isPalindrome(arr, i) && isPalindrome(arr1, j))
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}

OJ98
个人总结:将字符串输入到 str[] 数组中,遍历数组 str[](遍历到 len 以便处理最后一个数),若 str[i] 不为 + 且 i < len,使用 num 存储每一个数字(每个数字初始为0,即 num = 0),每往后遍历一个数字,num = num * 10 + str[i] - '0',直至遍历到 '+' 时,表明一个数字 num 被遍历完成,令sum += num ,随后令 num = 0,开始遍历下一个数字,直至遍历完整个数组

#include <stdio.h>
#include <string.h>
#define MAX_SIZE 99999
int main(){
    char str[MAX_SIZE];
    while(scanf("%s", str) != EOF){
        int len = strlen(str), sum = 0;
        int num = 0;
        for(int i = 0; i <= len; i++){
            if(str[i] != '+' && i < len){
                num = num * 10 + str[i] - '0';
            }
            else{
                sum += num;
                num = 0;
            }
        }
        printf("%d\n", sum);
    }
    return 0;
}

OJ99

个人总结:从第二轮开始循环到第九轮,每一轮取上一轮的序列长度 pre_len = strlen(str[i - 2]),m 指向新序列的当前位置,遍历上一轮序列的每个字符,将上一轮的字符赋值给这一轮序列(str[i - 1][m++] = str[i - 2][j])后,如果当前不是上一轮序列的最后一个字符,检查是否需要插入新的数字,判断相邻两个数字的和是否等于当前轮次数,若等于,插入当前轮次数字(str[i - 1][m++] = i + '0');遍历完第九轮后,序列生成完毕

#include <stdio.h>
#include <string.h>
#define MAX_SIZE 99999
int main(){
    char str[9][MAX_SIZE];
    strcpy(str[0], "11");//初始化第1轮序列
    for(int i = 2; i <= 9; i++){
        int pre_len = strlen(str[i - 2]);
        int m = 0;
        for(int j = 0; j < pre_len; j++){
            str[i - 1][m++] = str[i - 2][j];
            if(j < pre_len - 1){
                int num1 = str[i - 2][j] - '0';
                int num2 = str[i - 2][j + 1] - '0';
                if(num1 + num2 == i){//第n轮,每两个相邻的和为n的数之间插入n
                    str[i - 1][m++] = i + '0';
                }
            }
        }
    }
    int n;
    while(scanf("%d", &n) != EOF){
        printf("%s\n", str[n - 1]);
    }
    return 0;
}

Overfitting is a common problem during the training of machine learning models. When a model performs extremely well on training data but poorly on test data, it is considered to suffer from overfitting. This usually occurs when the model is too complex or when the amount of training data is insufficient. To reduce overfitting, researchers have proposed various techniques such as regularization, data augmentation, and cross-validation. Regularization methods introduce penalty terms into the loss function to limit the magnitude of model parameters, thereby making the model simpler and more stable. Data augmentation increases the diversity of training data by applying operations such as rotation, cropping, or adding noise to the original data. In addition, cross-validation evaluates the generalization ability of a model by repeatedly splitting the dataset into training and validation sets. These techniques can effectively improve the performance of machine learning models in real-world applications.

过拟合是机器学习模型训练过程中常见的问题。当一个模型在训练数据上表现极好,但在测试数据上表现很差时,就认为该模型出现了过拟合。这种情况通常发生在模型过于复杂或训练数据量不足时。为了减少过拟合,研究者们提出了多种方法,例如正则化、数据增强和交叉验证。正则化方法在损失函数中引入惩罚项,以限制模型参数的大小,从而使模型更简单、更稳定。数据增强通过对原始数据进行旋转、裁剪或添加噪声等操作来增加训练数据的多样性。此外,交叉验证通过将数据集反复划分为训练集和验证集来评估模型的泛化能力。这些方法能够有效提升机器学习模型在实际应用中的表现。

Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐