1062 Talent and Virtue

part 2, 2.1

自己解法

  • 认真读题!(惨痛教训)
#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>class person
{
public:person(int ID, int V, int T, int H){this->ID = ID;this->V = V;this->T = T;this->sum = V + T;if (V >= H && T >= H)this->flag = 1;else if (V >= H && T < H)this->flag = 2;else if (V < H && V >= T)this->flag = 3;elsethis->flag = 4;}int ID;int V, T;int sum, flag; // flag = 1 是 sages(V>=H,T>=H),flag = 2 是 nobleman(V>=H,T<H), flag = 3 是 foolman(T=<V<H)
};bool cmp(person a, person b)
{return a.flag != b.flag ? a.flag < b.flag : (a.sum != b.sum ? a.sum > b.sum : (a.V != b.V ? a.V > b.V : a.ID < b.ID));
}int main()
{int N, L, H;cin >> N >> L >> H;vector<person> v;for (int i = 0; i < N; i++){int ID, V, T;cin >> ID >> V >> T;if (V >= L && T >= L){person p(ID, V, T, H);v.push_back(p);}}sort(v.begin(), v.end(), cmp);int v_size = v.size();cout << v_size << endl;for (int i = 0; i < v_size; i++)cout << v[i].ID << " " << v[i].V << " " << v[i].T << endl;system("pause");return 0;
}

大神解法

  • 柳神
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct node {int num, de, cai;
};
int cmp(struct node a, struct node b) {if ((a.de + a.cai) != (b.de + b.cai))return (a.de + a.cai) > (b.de + b.cai);else if (a.de != b.de)return a.de > b.de;elsereturn a.num < b.num;
}
int main() {int n, low, high;scanf("%d %d %d", &n, &low, &high);vector<node> v[4];node temp;int total = n;for (int i = 0; i < n; i++) {scanf("%d %d %d", &temp.num, &temp.de, &temp.cai);if (temp.de < low || temp.cai < low)total--;else if (temp.de >= high && temp.cai >= high)v[0].push_back(temp);else if (temp.de >= high && temp.cai < high)v[1].push_back(temp);else if (temp.de < high && temp.cai < high && temp.de >= temp.cai)v[2].push_back(temp);elsev[3].push_back(temp);}printf("%d\n", total);for (int i = 0; i < 4; i++) {sort(v[i].begin(), v[i].end(), cmp);for (int j = 0; j < v[i].size(); j++)printf("%d %d %d\n", v[i][j].num, v[i][j].de, v[i][j].cai);}return 0;
}

PAT-1062 Talent and Virtue相关推荐

  1. PAT-B 1015. 德才论(同PAT 1062. Talent and Virtue)

    1. 在排序的过程中,注意边界的处理(小于.小于等于) 2. 对于B-level,这题是比較麻烦一些了. 源代码: #include <cstdio> #include <vecto ...

  2. PAT甲级1062 Talent and Virtue:[C++题解]结构体、哈希表

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析: 分4个vector,单独排序即可. ac代码 #include<bits/stdc++.h> using namespa ...

  3. PAT 甲级 1062 Talent and Virtue

    1062 Talent and Virtue 题目大意:给出一组人数,按照要求分类再排序输出.圣人是virtue和talent都超过h的人,君子是virtue超过h并且talent位于[l,h)区间内 ...

  4. PAT A1062 Talent and Virtue (25分)

    题意:德才均大于及格线low的才进行排序,排序的人按种姓分为 :) sages-nobleman-fool man-trash 对于人的类型的排序只需要在结构体中加入一个int type即可,通过这个 ...

  5. 1062 Talent and Virtue (25 分)

    1062 Talent and Virtue (25 分) 题意 先给出三个数N(成员人数),L(及格线),H(优秀线) 给出一组成员信息,包括id,品德,才能,给这组成员排序. 当该成员品德和才能都 ...

  6. 1062 Talent and Virtue 25

    1062 Talent and Virtue 25 题目链接:A1062 Talent and Virtue 25 问题思路 我尝试了两种思路: 根据每个人的分数确定其是哪个级别(rank)的人,以总 ...

  7. 1062. Talent and Virtue (25)-PAT甲级真题

    About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about ...

  8. PAT甲级1062 Talent and Virtue

    About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about ...

  9. 1062. Talent and Virtue (25)

    About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about ...

  10. 1062 Talent and Virtue(排序)

    这类题目归结于常用技巧与算法,有很鲜明的套路,重在理解其规则,通常写起来不算太复杂. 题目描述: 题目大致意思: 输入N和最低下限和最高上限,接着输入N个人的编号,美德和天赋.如果美德和天赋都不低于最 ...

最新文章

  1. 基于MATLAB的RGB转YCBCR色彩空间转换
  2. C++list常用接口总结
  3. 【收藏】Harbor私有仓库中如何彻底删除镜像释放存储空间:vmware/registry:2.6.2-photon进行垃圾回收
  4. Oracle ORA-07445 [evaopn3()+384] 错误 分析
  5. Linux 启动流程即init程序分析--2
  6. asp.net下载文件的常用方法大全
  7. 一个老者给年轻人的几个忠告
  8. 伪元素选择器使用场景-字体图标(CSS3)
  9. Redis:四、jedis连接redis服务器
  10. Executors介绍
  11. 【TSP】基于matlab改进的蚁群算法求解旅行商问题【含Matlab源码 242期】
  12. 这些年,我工作上走过的路
  13. 肯耐珂萨java_站在尤里奇的肩膀上,肯耐珂萨探讨适用于国内的HR胜任力模型
  14. matlab 方位角 经纬度,经纬度转方位角matlab程序
  15. apktool java_apktool 简单使用记录
  16. JavaScript中0.1+0.2问题
  17. 中国人寿保费项目数据集
  18. 【C/C++学习笔记】C++11 Lambda 表达式 (匿名函数)(TR1)
  19. 健康菜谱微信小程序+项目前后台源码(JavaSSM+Mysql)
  20. swagger配置使用及安全方案

热门文章

  1. flask_socketio
  2. js-实现选号器功能
  3. 从零开始之驱动发开、linux驱动(三十三、PWM子系统)
  4. Java 创建文件时 创建文件夹
  5. 短信删了怎样找回信息
  6. DS1302时钟芯片
  7. 工作区域(或内部表)“LT_RKWA“不是扁平的,或者包含参考或内部表作为组件
  8. wxml报错原因_微信小程序开发教程(八)视图层——.wxml详解
  9. k30pro刷鸿蒙,k30pro没有高刷的个人看法
  10. 【附源码】计算机毕业设计java疫情下公共场所卫生安全管理系统设计与实现