PAT程序设计考题——甲级1017(Queueing at Bank ) C++实现

点击打开pat链接#include<iostream>
#include<math.h>
#include<algorithm>
#include<map>
#include<stack>
#include<string>
#include<vector>
using namespace std;
#define INF 100000000
#define maxn 100010
struct customer{
 int time,sertime;
}newcustomer;
bool cmp(customer a,customer b)
{
 return a.time<b.time;
}
int main(){
 int n,k;
 double sum=0;
 cin>>n>>k;
 int endtime[maxn]={0};
 int h,m,s,sert;
 int temp;
 vector<customer> guest;
 for(int i=0;i<n;i++)
 {
  scanf("%d:%d:%d %d",&h,&m,&s,&sert);
 temp=h*3600+m*60+s;
  if(sert>60) sert=60;
  newcustomer.sertime=sert*60;
  newcustomer.time=temp;
  if(temp<17*3600) guest.push_back(newcustomer);
   }
sort(guest.begin(),guest.end(),cmp);
int stime=8*3600;
for(int i=0;i<k;i++)
endtime[i]=stime;
int store,id,j;
for(int i=0;i<guest.size();i++)
 
{store=INF,id=-1;
 for(j=0;j<k;j++)
{ if(endtime[j]<store) {
store=endtime[j];
id=j; 
}}
//cout<<id<<store<<guest[0].time;
if(store>guest[i].time) {sum+=(endtime[id]-guest[i].time);
endtime[id]+=guest[i].sertime;
}
else endtime[id]=guest[i].time+guest[i].sertime;
}
double ave=sum/60/guest.size();
printf("%.1lf",ave);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值