Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:Discuss区中的所有测试用例全过,但是仍然WA,求大神指点迷津!

Posted by qw885 at 2018-03-14 12:56:06 on Problem 2376
In Reply To:Discuss区中的所有测试用例全过,但是仍然WA,求大神指点迷津! Posted by:TheIllsionist at 2018-01-30 15:52:45
> 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator