P1786 帮贡排序
Posted Pannnn
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了P1786 帮贡排序相关的知识,希望对你有一定的参考价值。
// Problem: P1786 帮贡排序
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1786
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// User: Pannnn
#include <bits/stdc++.h>
using namespace std;
struct People
string name;
string position;
int contribute;
int grade;
int id;
;
void adjust(vector<pair<string, int>> &posInfo, map<string, int> &posMap, vector<People> &info)
// 按照帮贡排序,如果帮贡一样,按输入顺序排列
sort(info.begin(), info.end(), [](People p1, People p2) -> bool
if (p1.contribute != p2.contribute)
return p1.contribute > p2.contribute;
else
return p1.id < p2.id;
);
int idx = 0;
for (int i = 0; i < info.size(); ++i)
if (!info[i].position.empty())
continue;
while (posInfo[idx].second == 0) ++idx;
info[i].position = posInfo[idx].first;
--posInfo[idx].second;
// 按现在职位排序,如职位相同,再按等级排序,如等级一样,按输入顺序排列
sort(info.begin(), info.end(), [&posMap](People p1, People p2)-> bool
if (posMap[p1.position] != posMap[p2.position])
return posMap[p1.position] < posMap[p2.position];
else if (p1.grade != p2.grade)
return p1.grade > p2.grade;
else
return p1.id < p2.id;
);
int main()
int n;
cin >> n;
vector<pair<string, int>> posInfo"BangZhu", 1, "FuBangZhu", 2, "HuFa", 2,
"ZhangLao", 4, "TangZhu", 7, "JingYing", 25, "BangZhong", INT_MAX;
map<string, int> posMap"BangZhu", 0, "FuBangZhu", 1,
"HuFa", 2, "ZhangLao", 3, "TangZhu", 4, "JingYing", 5, "BangZhong", 6;
vector<People> info(n);
for (int i = 0; i < n; ++i)
cin >> info[i].name >> info[i].position >> info[i].contribute >> info[i].grade;
info[i].id = i;
if (info[i].position == "BangZhu" || info[i].position == "FuBangZhu")
--posInfo[posMap[info[i].position]].second;
else
info[i].position.clear();
adjust(posInfo, posMap, info);
for (int i = 0; i < info.size(); ++i)
cout << info[i].name << " " << info[i].position << " " << info[i].grade << endl;
return 0;
以上是关于P1786 帮贡排序的主要内容,如果未能解决你的问题,请参考以下文章
插入排序(直接插入排序希尔排序);交换排序(冒泡排序快速排序);选择排序(简单选择排序堆排序);归并排序和基数排序;基于关键词比较的排序算法下界分析
九种经典排序算法详解(冒泡排序,插入排序,选择排序,快速排序,归并排序,堆排序,计数排序,桶排序,基数排序)
冒泡排序,快速排序,归并排序,插入排序,希尔排序,堆排序,计数排序,桶排序,基数排序
常见排序算法的实现(归并排序快速排序堆排序选择排序插入排序希尔排序)