1062 Talent and Virtue (25分)

关于900年前,中国哲学家司马光在历史书中阐述了人们的才能与德行,根据他的理论,才能与德行兼备者为圣人;德行胜过才能者为君子;两者皆不具备者为愚人;而小人则偏好才能甚于德行。此文章详细介绍了一种基于司马光理论的人才排名算法,通过设定不同的评价标准,将人们分为圣人、君子、愚人及小人四个等级,并根据各自的总分进行排名。

About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a "sage(圣人)"; being less excellent but with one's virtue outweighs talent can be called a "nobleman(君子)"; being good in neither is a "fool man(愚人)"; yet a fool man is better than a "small man(小人)" who prefers talent than virtue.

Now given the grades of talent and virtue of a group of people, you are supposed to rank them according to Sima Guang's theory.

Input Specification:

Each input file contains one test case. Each case first gives 3 positive integers in a line: N (≤10​5​​), the total number of people to be ranked; L (≥60), the lower bound of the qualified grades -- that is, only the ones whose grades of talent and virtue are both not below this line will be ranked; and H (<100), the higher line of qualification -- that is, those with both grades not below this line are considered as the "sages", and will be ranked in non-increasing order according to their total grades. Those with talent grades below H but virtue grades not are cosidered as the "noblemen", and are also ranked in non-increasing order according to their total grades, but they are listed after the "sages". Those with both grades below H, but with virtue not lower than talent are considered as the "fool men". They are ranked in the same way but after the "noblemen". The rest of people whose grades both pass the L line are ranked after the "fool men".

Then N lines follow, each gives the information of a person in the format:

ID_Number Virtue_Grade Talent_Grade

where ID_Number is an 8-digit number, and both grades are integers in [0, 100]. All the numbers are separated by a space.

Output Specification:

The first line of output must give M (≤N), the total number of people that are actually ranked. Then M lines follow, each gives the information of a person in the same format as the input, according to the ranking rules. If there is a tie of the total grade, they must be ranked with respect to their virtue grades in non-increasing order. If there is still a tie, then output in increasing order of their ID's.

Sample Input:

14 60 80
10000001 64 90
10000002 90 60
10000011 85 80
10000003 85 80
10000004 80 85
10000005 82 77
10000006 83 76
10000007 90 78
10000008 75 79
10000009 59 90
10000010 88 45
10000012 80 100
10000013 90 99
10000014 66 60

Sample Output:

12
10000013 90 99
10000012 80 100
10000003 85 80
10000011 85 80
10000004 80 85
10000007 90 78
10000006 83 76
10000005 82 77
10000002 90 60
10000014 66 60
10000008 75 79
10000001 64 90

题目:排序,直接用sort,外加一个自己定义的规则,就可以A~

#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
struct node{
    int id;
    int vir_score;
    int tal_score;
    int flag;

};
bool cmp(node a, node b){
    if(a.flag != b.flag){
        return a.flag < b.flag;
    }else if(a.tal_score + a.vir_score != b.tal_score + b.vir_score)
    {
        return a.tal_score + a.vir_score > b.tal_score + b.vir_score;
    }else
    {
        return a.vir_score != b.vir_score ? a.vir_score > b.vir_score : a.id < b.id;
    }
    
    

}
int main(){
    int n, l, h;
    cin >> n >> l >> h;
    vector<node> vec;
    for(int i = 0; i < n; i++){
        node temp;
       
        scanf("%d %d %d", &temp.id, &temp.vir_score, &temp.tal_score);
        if(temp.vir_score >=l && temp.tal_score >= l){
            if(temp.vir_score >= h && temp.tal_score >= h){
                temp.flag = 1;
                vec.push_back(temp);

            }else if(temp.vir_score >= h &&  temp.tal_score < h)
            {
                temp.flag = 2;
                vec.push_back(temp);
            }else if(temp.vir_score < h &&  temp.tal_score < h && temp.tal_score <= temp.vir_score)
            {
                temp.flag = 3;
                vec.push_back(temp);
            }else
            {
                temp.flag = 4;
                vec.push_back(temp);
            }
        
        }
        
        
        

    }
    sort(vec.begin(), vec.end(), cmp);
    printf("%d\n", int(vec.size()));
    for(int i = 0; i < vec.size(); i++){
        printf("%08d %d %d\n", vec[i].id, vec[i].vir_score, vec[i].tal_score);
    }
    return 0;
}

 

内容概要:本文围绕六自由度机械臂的人工神经网络(ANN)设计展开,重点研究了正向与逆向运动学求解、正向动力学控制以及基于拉格朗日-欧拉法推导逆向动力学方程,并通过Matlab代码实现相关算法。文章结合理论推导与仿真实践,利用人工神经网络对复杂的非线性关系进行建模与逼近,提升机械臂运动控制的精度与效率。同时涵盖了路径规划中的RRT算法与B样条优化方法,形成从运动学到动力学再到轨迹优化的完整技术链条。; 适合人群:具备一定机器人学、自动控制理论基础,熟悉Matlab编程,从事智能控制、机器人控制、运动学六自由度机械臂ANN人工神经网络设计:正向逆向运动学求解、正向动力学控制、拉格朗日-欧拉法推导逆向动力学方程(Matlab代码实现)建模等相关方向的研究生、科研人员及工程技术人员。; 使用场景及目标:①掌握机械臂正/逆运动学的数学建模与ANN求解方法;②理解拉格朗日-欧拉法在动力学建模中的应用;③实现基于神经网络的动力学补偿与高精度轨迹跟踪控制;④结合RRT与B样条完成平滑路径规划与优化。; 阅读建议:建议读者结合Matlab代码动手实践,先从运动学建模入手,逐步深入动力学析与神经网络训练,注重理论推导与仿真实验的结合,以充理解机械臂控制系统的设计流程与优化策略。
### C++ 中的虚函数概念 #### 定义与作用 在面向对象编程中,为了实现多态机制,C++引入了虚函数的概念。通过关键字`virtual`声明成员函数为虚函数之后,允许派生类重写此方法并动态绑定到具体实例上[^1]。 #### 声明方式 要在基类中定义一个普通的虚函数,只需简单地在其前加上`virtual`修饰符即可: ```cpp class Base { public: virtual void show() { cout << "Base class"; } }; ``` 对于派生类而言,则可以通过覆盖(即使用相同的签名重新定义)这些被标记成虚拟的方法来改变行为: ```cpp class Derived : public Base{ public: void show() override{cout<<"Derived class";} }; ``` 这里需要注意的是,在现代C++标准里推荐显式指定`override`以表明意图并且防止拼写错误引发的问题[^2]。 #### 动态派过程解析 每当创建含有至少一个虚函数的对象时,编译器会自动为其配一块隐藏区域用于保存指向_vtable_(虚函数表)的指针。而_vptr_(虚表指针)则始终位于对象内存布局最前端位置以便快速访问。当调用某个可能涉及继承体系内不同版本的选择时,程序运行期间将会依据当前实际类型的_vptr_所指示的位置去查找对应的目标地址完成最终跳转操作[^3]。 ```cpp #include <iostream> using namespace std; // 定义基类 class Animal { protected: string name; public: explicit Animal(const char* n):name(n){} virtual ~Animal(){} virtual void speak(){cout<<this->name<<" makes a sound.";} }; // 继承自基类的新类型 class Dog : public Animal { public: using Animal::Animal; // 使用父级构造参数初始化列表简化语法糖 void speak() override { cout << this->name << " barks loudly."; } }; int main(){ auto p_animal = new Dog("Rex"); p_animal->speak(); // 输出:"Rex barks loudly." delete p_animal; return 0; } ``` 上述例子展示了如何利用虚函数特性让同一接口表达出多种不同的语义逻辑,从而达到更加灵活的设计目的。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值