64,645
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;
const int MAX=10086;
typedef struct QJKcustomer
{
int arrivingtime;
int waitingtime;
int inservingtime;
int tooearly;
};
int compare(const void *a,const void *b)
{
int aa=*(int *)a;
int bb=*(int *)b;
return aa-bb;
}
QJKcustomer customer[MAX];
int HASH[110];
int main()
{
int N,K;
scanf("%d%d",&N,&K);
int index=0;
for(int i=0;i<N;++i)
{
int hh,mm,ss,is;
scanf("%d:%d:%d %d",&hh,&mm,&ss,&is);
if(hh<8)
{
customer[index].tooearly=8*3600-(hh*3600+mm*60+ss);
hh=8,mm=0,ss=0;
}
else if(hh>=17)continue;
hh-=8;
customer[index].arrivingtime=hh*3600+mm*60+ss;
customer[index].inservingtime=is*60;
++index;
}
qsort(customer,index,sizeof(QJKcustomer),compare);
int j=0,f=0;
memset(HASH,customer[0].arrivingtime,K);
while(f<index)
{
qsort(HASH,K,sizeof(int),compare);
if(HASH[0]>customer[f].arrivingtime+customer[f].waitingtime)
{
int needwait=HASH[0]-(customer[f].arrivingtime+customer[f].waitingtime);
for(int i=f;i<index;++i)
{
customer[i].waitingtime+=needwait;
}
HASH[0]+=customer[f].inservingtime;
++f;
}
else if(HASH[0]==customer[f].arrivingtime+customer[f].waitingtime)
{
HASH[0]+=customer[f].inservingtime;
++f;
}
else if(HASH[0]<customer[f].arrivingtime+customer[f].waitingtime)
{
int noneedwait=customer[f].arrivingtime+customer[f].waitingtime-HASH[0];
customer[f].waitingtime-=noneedwait;
HASH[0]+=customer[f].inservingtime;
++f;
}
}
int totalwaitingtime=0;
for(int i=0;i<index;++i)
{
totalwaitingtime+=customer[i].waitingtime+customer[i].tooearly;
}
printf("%.1f",totalwaitingtime/(index*60.0));
return 0;
}
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;
const int MAX=10086;
typedef struct QJKcustomer
{
int arrivingtime;
int waitingtime;
int inservingtime;
int tooearly;
};
int compare(const void *a,const void *b)
{
QJKcustomer aa=*(QJKcustomer *)a;
QJKcustomer bb=*(QJKcustomer *)b;
return aa.arrivingtime-bb.arrivingtime;
}
int COMPARE(const void *a,const void *b)
{
int aa=*(int *)a;
int bb=*(int *)b;
return aa-bb;
}
QJKcustomer customer[MAX];
int HASH[110];
int main()
{
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
int N,K;
scanf("%d%d",&N,&K);
int index=0;
for(int i=0;i<N;++i)
{
int hh,mm,ss,is;
scanf("%d:%d:%d %d",&hh,&mm,&ss,&is);
if(hh<17)
{
customer[index].arrivingtime=hh*3600+mm*60+ss;
customer[index].inservingtime=is*60;
++index;
}
else if(hh>=17)continue;
}
qsort(customer,index,sizeof(QJKcustomer),compare);
for(int i=0;i<index;++i)
{
if(customer[i].arrivingtime<8*3600)
{
customer[i].tooearly=8*3600-customer[i].arrivingtime;
customer[i].arrivingtime=0;
}
else customer[i].arrivingtime-=8*3600;
}
int j=0,f=0;
memset(HASH,customer[0].arrivingtime,K);
while(f<index)
{
qsort(HASH,K,sizeof(int),COMPARE);
if(HASH[0]>customer[f].arrivingtime+customer[f].waitingtime)
{
int needwait=HASH[0]-(customer[f].arrivingtime+customer[f].waitingtime);
for(int i=f;i<index;++i)
{
customer[i].waitingtime+=needwait;
}
HASH[0]+=customer[f].inservingtime;
++f;
}
else if(HASH[0]==customer[f].arrivingtime+customer[f].waitingtime)
{
HASH[0]+=customer[f].inservingtime;
++f;
}
//前一楼层的代码这里改的不好,完善了下直接AC
else if(HASH[0]<customer[f].arrivingtime+customer[f].waitingtime)
{
if(HASH[0]>=customer[f].arrivingtime)
{
customer[f].waitingtime=HASH[0]-customer[f].arrivingtime;
HASH[0]+=customer[f].inservingtime;
}
else
{
HASH[0]=customer[f].arrivingtime+customer[f].inservingtime;
customer[f].waitingtime=0;
}
++f;
}
}
int totalwaitingtime=0;
for(int i=0;i<index;++i)
{
totalwaitingtime+=customer[i].waitingtime+customer[i].tooearly;
}
printf("%.1f",totalwaitingtime/(index*60.0));
return 0;
}
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;
const int MAX=10086;
typedef struct QJKcustomer
{
int arrivingtime;
int waitingtime;
int inservingtime;
int tooearly;
};
int compare(const void *a,const void *b)
{
QJKcustomer aa=*(QJKcustomer *)a;
QJKcustomer bb=*(QJKcustomer *)b;
return aa.arrivingtime-bb.arrivingtime;
}
int COMPARE(const void *a,const void *b)
{
int aa=*(int *)a;
int bb=*(int *)b;
return aa-bb;
}
QJKcustomer customer[MAX];
int HASH[110];
int main()
{
int N,K;
scanf("%d%d",&N,&K);
int index=0;
for(int i=0;i<N;++i)
{
int hh,mm,ss,is;
scanf("%d:%d:%d %d",&hh,&mm,&ss,&is);
if(hh<17)
{
customer[index].arrivingtime=hh*3600+mm*60+ss;
customer[index].inservingtime=is*60;
++index;
}
else if(hh>=17)continue;
}
qsort(customer,index,sizeof(QJKcustomer),compare);
for(int i=0;i<index;++i)
{
if(customer[i].arrivingtime<8*3600)
{
customer[i].tooearly=8*3600-customer[i].arrivingtime;
customer[i].arrivingtime=0;
}
else customer[i].arrivingtime-=8*3600;
}
int j=0,f=0;
memset(HASH,customer[0].arrivingtime,K);
while(f<index)
{
qsort(HASH,K,sizeof(int),COMPARE);
if(HASH[0]>customer[f].arrivingtime+customer[f].waitingtime)
{
int needwait=HASH[0]-(customer[f].arrivingtime+customer[f].waitingtime);
for(int i=f;i<index;++i)
{
customer[i].waitingtime+=needwait;
}
HASH[0]+=customer[f].inservingtime;
++f;
}
else if(HASH[0]==customer[f].arrivingtime+customer[f].waitingtime)
{
HASH[0]+=customer[f].inservingtime;
++f;
}
//下面是修改的部分
else if(HASH[0]<customer[f].arrivingtime+customer[f].waitingtime)
{
int noneedwait=customer[f].arrivingtime+customer[f].waitingtime-HASH[0];
if(customer[f].waitingtime>=noneedwait)customer[f].waitingtime-=noneedwait;
else
{
if(HASH[0]<=customer[f].arrivingtime)
{
HASH[0]=customer[f].arrivingtime+customer[f].inservingtime;
customer[f].waitingtime=0;
}
else
{
customer[f].waitingtime=HASH[0]-customer[f].arrivingtime;
HASH[0]+=customer[f].inservingtime;
}
}
++f;
}
}
int totalwaitingtime=0;
for(int i=0;i<index;++i)
{
totalwaitingtime+=customer[i].waitingtime+customer[i].tooearly;
}
printf("%.1f",totalwaitingtime/(index*60.0));
return 0;
}