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);
}
#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);
}
相关文章推荐
- PAT程序设计考题——甲级1040 (最长回文串) C++实现
- PAT程序设计考题——甲级1007 (最大连续子序列和) C++实现
- PAT程序设计考题——甲级1036( Boys vs Girls ) C++实现
- PAT程序设计考题——甲级1057( stock 分块查询) C++实现
- PAT程序设计考题——甲级1030(Travel Plan) C++实现
- PAT程序设计考题——甲级1068 (背包问题) C++实现
- PAT程序设计考题——甲级1006(Sign In and Sign Out ) C++实现
- PAT程序设计考题——甲级1077(Kuchiguse ) C++实现
- PAT程序设计考题——甲级1003(Emergency ) C++实现
- PAT程序设计考题——甲级1107( Social clusters并查集) C++实现
- PAT程序设计考题——甲级1082( Read Number in Chinese ) C++实现
- PAT程序设计考题——甲级1042(洗牌机) C++实现
- PAT程序设计考题——甲级1008( elevator) C++实现
- PAT程序设计考题——甲级1043(Is It a Binary Search Tree ) C++实现
- PAT程序设计考题——甲级1019( General Palindromic Number ) C++实现
- PAT程序设计考题——甲级1066(Root of AVL Tree ) C++实现
- PAT程序设计考题——甲级1011( World Cup Betting ) C++实现
- PAT程序设计考题——甲级1020( Tree traverse ) C++实现
- PAT程序设计考题——甲级1058(A+B in Hogwarts ) C++实现
- PAT程序设计考题——甲级1014( Waiting in Line ) C++实现