您的位置:首页 > 编程语言 > C语言/C++

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

2017-06-24 01:46 615 查看
点击打开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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: