假设银行有K个窗口提供服务,窗口前设一条黄线,所有顾客按到达时间在黄线后排成一条长龙。当有窗口空闲时,下一位顾客即去该窗口处理事务。当有多个窗口可选择时,假设顾客总是选择编号最小的窗口。
本题要求输出前来等待服务的N位顾客的平均等待时间、最长等待时间、最后完成时间,并且统计每个窗口服务了多少名顾客。
输入格式:
输入第1行给出正整数N(≤1000),为顾客总人数;随后N行,每行给出一位顾客的到达时间T和事务处理时间P,并且假设输入数据已经按到达时间先后排好了顺序;最后一行给出正整数K(≤10),为开设的营业窗口数。这里假设每位顾客事务被处理的最长时间为60分钟。
输出格式:
在第一行中输出平均等待时间(输出到小数点后1位)、最长等待时间、最后完成时间,之间用1个空格分隔,行末不能有多余空格。
在第二行中按编号递增顺序输出每个窗口服务了多少名顾客,数字之间用1个空格分隔,行末不能有多余空格。
输入样例:
2
5
1234567890001 95
1234567890005 100
1234567890003 95
1234567890002 77
1234567890004 85
4
1234567890013 65
1234567890011 25
1234567890014 100
1234567890012 85
输出样例:
9
1234567890005 1 1 1
1234567890014 1 2 1
1234567890001 3 1 2
1234567890003 3 1 2
1234567890004 5 1 4
1234567890012 5 2 2
1234567890002 7 1 5
1234567890013 8 2 3
1234567890011 9 2 4
题目思路:
设置一个结构体,用于存储用到的信息。然后建立对应的结构体数组,保证“小组有序”和“整体有序”。
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
struct Student {
string st; //学号
int score; //分数
int groupID;//考场号
int grouprank;//在考场中的等级
int allrank;//总排名
}student[30005];
bool cmp(Student a, Student b)
{
if (a.score == b.score) //分数相等,按学号增序
return a.st < b.st;
else
return a.score > b.score; //正常按分数从大到小
}
int main()
{
int n;
cin >> n;
int sum = 0;
for (int i = 1; i <= n; i++)
{
int k;
cin >> k;
for (int j = sum; j < sum + k; j++)
{
cin >> student[j].st >> student[j].score;
student[j].groupID = i;
}
sort(student + sum, student + k + sum, cmp);
student[sum].grouprank = 1; //每个考场中第一名的排名是1
for (int j = sum + 1; j < sum + k; j++) //确定每个小组之间的排名
{
if (student[j].score == student[j - 1].score)
student[j].grouprank = student[j - 1].grouprank;
else
student[j].grouprank = j-sum+1;
}
sum += k; //算得总体人数
}
sort(student, student + sum, cmp);
student[0].allrank = 1; //和上面一致,分数最高的排名第一
for (int j = 1; j < sum; j++)
{
if (student[j].score == student[j - 1].score)
student[j].allrank = student[j - 1].allrank;
else
student[j].allrank = j+1;
}
cout << sum << endl;
for (int i = 0; i < sum; i++)
{
cout << student[i].st << " " << student[i].allrank << " " << student[i].groupID << " " << student[i].grouprank << endl;
}
return 0;
}