牛牛的闹钟

牛牛总是睡过头,所以他定了很多闹钟,只有在闹钟响的时候他才会醒过来并且决定起不起床。从他起床算起他需要X分钟到达教室,上课时间为当天的A时B分,请问他最晚可以什么时间起床 

输入描述:

每个输入包含一个测试用例。
每个测试用例的第一行包含一个正整数,表示闹钟的数量N(N<=100)。
接下来的N行每行包含两个整数,表示这个闹钟响起的时间为Hi(0<=A<24)时Mi(0<=B<60)分。
接下来的一行包含一个整数,表示从起床算起他需要X(0<=X<=100)分钟到达教室。
接下来的一行包含两个整数,表示上课时间为A(0<=A<24)时B(0<=B<60)分。
数据保证至少有一个闹钟可以让牛牛及时到达教室。


 

输出描述:

输出两个整数表示牛牛最晚起床时间。

示例1

输入

3 
5 0 
6 0 
7 0 
59 
6 59

输出

6 0
(1)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main{
     public static void main(String[] args) {
    	 Scanner re = new Scanner(System.in);
    	 int n = re.nextInt();
    	 int i, s, time, a, b, f, p, st, en;
    	 int t[] = new int[105];
    	 for(i = 0; i < n; i++) {
    		 st = re.nextInt();
    		 en = re.nextInt();
    		 t[i] = st * 60 + en;
    	 }
    	 s = re.nextInt();
    	 a = re.nextInt(); b = re.nextInt();
    	 time = a * 60 + b - s;
    	 f = 0;
    	 for(i = 0; i < n; i++) {
    		 if(t[i]<=time) {
    			 if(t[i]>f)
    				 f = t[i];
    		 }
    	 }
    	 System.out.println(f/60+" "+f%60);
     }
}

(2)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main implements Comparable<Main>{
	int hour, ms, num;
	Main(int hour, int ms){
		hour = hour;
		ms = ms;
		num = hour * 60 + ms;
	}
     public static void main(String[] args) {
    	 Scanner re = new Scanner(System.in);
    	 int n = re.nextInt();
    	 int i, s, time, a, b, f=0, p;
    	 PriorityQueue<Main>pq = new PriorityQueue<>();
    	 while(n-- != 0)
    		 pq.add(new Main(re.nextInt(), re.nextInt()));
    	 s = re.nextInt();
    	 a = re.nextInt(); b = re.nextInt();
    	 time = a * 60 + b - s;
    	 while(pq.size()!=0) {
    		 p = pq.peek().num;
    		 if(p<=time) {
    			 if(p > f)
    				 f = p;
    		 }
    		 pq.poll();
    	 }
    	 System.out.println(f/60+" "+f%60);
     }

	@Override
	public int compareTo(Main o) {
		// TODO Auto-generated method stub
		return this.num - o.num;
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值