Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Discuss区中的所有测试用例全过,但是仍然WA,求大神指点迷津!import java.util.Scanner; public class Main{ public static void main(String args[]) { Scanner input = new Scanner(System.in); int N = input.nextInt(); int T = input.nextInt(); int[] intervals = new int[T + 1]; //下标代表开始时间,值代表结束时间,如果值为0,代表没有以下标为开始的段 int num = N; int maxStart = -1; while ((--num) >= 0) { int s = input.nextInt(); int e = input.nextInt(); maxStart = Math.max(maxStart, s); if(e > intervals[s] && e >= s){ intervals[s] = e; } } if (intervals[1] < 1 || intervals[maxStart] < T) { System.out.println(-1); return; } int count = 1; //计算总共需要多少牛 int i = 1; int e = intervals[i]; while (++i <= T) { if (e >= T) { //已覆盖所有时间段,退出 break; } int newE = 0; while (i <= T && i <= (e + 1)) { if (intervals[i] > newE) { newE = intervals[i]; } i++; } i--; if (newE == 0) { //中间有断裂情况 count = -1; break; } else { e = newE; count++; } } if (e >= T) { System.out.println(count); } else { System.out.println(-1); } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator