1062. Talent and Virtue (25)
来源:互联网 发布:婴儿床的好处 知乎 编辑:程序博客网 时间:2024/06/08 09:56
1. 原题: https://www.patest.cn/contests/pat-a-practise/1062
2. 思路:
题意:
结构体的内部排序。
思路:
排序题。由于是4个部分,所以用了4个vector。
注意不要用cin,超时。
结构体的内部排序。
思路:
排序题。由于是4个部分,所以用了4个vector。
注意不要用cin,超时。
3. 源码(已AC):
#include<iostream>#include<algorithm>//使用sort函数#include<vector>using namespace std;struct Node//分数结构体{Node(int d, int v, int t) : id(d), sg(v + t), vg(v), tg(t) {}//初始化bool operator<(const Node &b) const//重载比较运算符{if (sg != b.sg)return sg > b.sg;else{if (vg != b.vg)return vg > b.vg;elsereturn id < b.id;}}int id;int sg, vg, tg;//分别为总分,美德分数, 才能分数};int main(void){//freopen("in.txt", "r", stdin);int N, low, high;scanf("%d %d %d", &N, &low, &high);vector<Node> vec[4];Node t(1, 2, 3);int valid = 0;//有效人数for (int i = 0; i < N; i++){int id, v, t;scanf("%d %d %d", &id, &v, &t);Node tem(id, v, t);if (v < low || t < low)//无效,读下一组数据continue;if (v >= high && t >= high)//放入合适的vector。vec[0].push_back(tem);else if (t < high && v >= high)vec[1].push_back(tem);else if (v >= t)vec[2].push_back(tem);elsevec[3].push_back(tem);valid++;}for (int i = 0; i < 4; i++)sort(vec[i].begin(), vec[i].end());printf("%d\n", valid);//输出for (int i = 0; i < 4; i++){for (int j = 0; j < vec[i].size(); j++)printf("%d %d %d\n", vec[i][j].id, vec[i][j].vg, vec[i][j].tg);}return 0;}
0 0
- 1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)
- linux-c 语言第一次尝试编译和运行
- 使用C#压缩解压文件
- 在版本问题上解决 org.hibernate.MappingException: Unknown entit xxx
- 最终排名 (sdut oj)
- RT-Thread - 笔记1:使用STM32F0 官方BSP跑起来
- 1062. Talent and Virtue (25)
- Android自定义相机之Camera1
- [BZOJ3218][UOJ#77]A+B Problem(可持久化线段树+最小割)
- numpy矩阵属性知识小结
- Git 本地创建分支并提交远程分支
- Android开发之旅
- 前端问题(7)
- WEB中前台JS控制打印PDF文件
- 基于SSH实现免密码登陆