部分(((φ(◎ロ◎;)φ)))
- vector使用sort排序:需要头文件
#include<algorithm>
, - 喵
sort(vec.begin(),vec.end());(默认是按升序排列,即从小到大).
#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue> // n^复杂度计算10000次,时间限制0.4s,为了不超时,球员要用堆,球台可以不用100,100————服务10000,遍历100次复杂度100*10000
using namespace std;
const int N = 10010, int M = 110;
struct Player
{
int arr_time;
int play_time;
int begin_time;
int wait_time;
bool operator< (const Player& t) const //⭐⭐sort排序,堆用大于号
{
if (begin_time != t.begin_time) begin_time < t.begin_time;
return arr_time < t.arr_time;
}
bool operator> (const Player& t) const //堆排序用大于号,优先队列中比较大小
{
return arr_time > t.arr_time;
}
}players[N];
struct Table
{
int nums_playerstable;
int end_time;
bool operator> (const Table& t) const //堆排序用 > ⭐
{
if (end_time != t.end_time) return end_time > t.end_time;
return id > t.id;
}
}
priority_queue<Player, vector<Player>, greater<Player>> normal_player;
priority_queue<Player, vector<Player>, greater<Player>> vip_player;
int mums_player, vip;
int mian()
{
cin >> nums_player;
int hour, minute, second, p_t, vip;
for (int i = 0; i < nums_player; i ++ )
{
scanf("%d:%d:%d %d %d", &hour, &minute, &second, &p_t, &vip );
int day_time = hour * 3600 + minute * 60 + second;
if(vip) vip_player.push_back({day_time, p_t});
else normal_player.push_back({day_time, p_t});
}
}
mian()??