[PAT]甲级1017

[PAT]甲级1017

// An highlighted block
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
		String[] number=new String[2];
		number=read.readLine().split(" ");
		int numOfCustomer=Integer.valueOf(number[0]);
		int numOfWindows=Integer.valueOf(number[1]);
		String[] temp1=new String[2];
		String[] time=new String[3];
		int temp2;
		ArrayList<Customer> customer= new ArrayList<Customer>();
		//creat customer
		for(int i=0;i<numOfCustomer;i++){
			temp1=read.readLine().split(" ");
			time=temp1[0].split(":");
			temp2=Integer.valueOf(time[0])*3600+Integer.valueOf(time[1])*60+Integer.valueOf(time[2]);
			Customer temp3=new Customer(temp2,temp1[1]);
			if(temp2>61200) continue;
			customer.add(temp3);
		}
		if(customer.size()==0){
			System.out.print("0");
			return;
			}
		//sort customer
		int mini,index=0;
		for(int i=0;i<customer.size()-1;i++){
			mini=customer.get(i).time;
			for(int j=i+1;j<customer.size();j++){
				if(mini>customer.get(j).time){
					mini=customer.get(j).time;
					index=j;
				}
			}
			Customer temp3=customer.get(i);
			customer.set(i,customer.get(index));
			customer.set(index,temp3);
		}
		int[] window=new int[numOfWindows];
		for(int i=0;i<numOfWindows;i++){
			window[i]=28800;
		}
		double reslust=0.0;
		for(int i=0;i<customer.size();i++){
			int miniFinish=window[0];
			int tempIndex=0;
			for(int j=1;j<numOfWindows;j++){
				if(miniFinish>window[j]){
					miniFinish=window[j];
					tempIndex=j;
				}
			}
			if(window[tempIndex]<=customer.get(i).time){
				window[tempIndex]=customer.get(i).time+customer.get(i).doingTime;
			}else{
				reslust+=(window[tempIndex]-customer.get(i).time);
				window[tempIndex]+=customer.get(i).doingTime;
			}
			
		}
		reslust=reslust/60/customer.size();
		System.out.print(String.format("%.1f",reslust));
		
	}
}
class Customer{
	int time;
	int doingTime;
	public Customer(int time1,String time2){
		time=time1;
		int a=(int)(Double.parseDouble(time2)*60);
		if(a>3600){
			doingTime=3600;
		}else{
			doingTime=a;
		}
		
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值