头条第一题,java,竟然超时。。。
发布于 2017-08-23 10:52 2045 次浏览 0 赞 来自 试题交流  

import java.util.*;

 

class Point{

int x,y;

public Point(int x, int y){

this.x = x;

this.y = y;

}

}

public class Main{

public static void main(String[] args){

Scanner sc = new Scanner(System.in);

int n = sc.nextInt();

int x = 0, y = 0;

Point[] points = new Point[n];

for(int i = 0 ; i < n ; i++){

x = sc.nextInt();

points[i] = new Point(x, sc.nextInt());

}

Arrays.sort(points, new Comparator<Point>(){

public int compare(Point arg1, Point arg2) {

// TODO Auto-generated method stub

return arg2.x -arg1.x;

}

});

int maxY = -1;

for (int i = 0 ; i < n; i++){

if(points[i].y > maxY){

maxY= points[i].y;

System.out.println(points[i].x+" "+points[i].y);

}

}

}

}


3 条回复

有没有AC了的能来指正一下,而且只过了10%,感觉不可能啊,明明50% 的数据在10000以内,这50%数据应该都过了才对。

2017-08-23 10:54

你是按x轴从大到小输出的

2017-08-23 11:15
coder_UnGGSLHZ 回复 acmcodernXkYTZ8V

扎心了。。。

2017-08-23 11:35
添加回复
回到顶部