全部评论
请问你是用的python写的吗? 我用的python,O(N2)的排序算法,按道理应该是可以通过的,但实际上,也是有20%的测试数据没通过
分享
import java.util.Arrays; import java.util.Scanner; public class Score_Line { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()) { int n = sc.nextInt(); int m = (int) Math.floor(sc.nextDouble()*1.5); p[] p = new p[n+1]; for(int i=1;i<=n;i++) { p[i] = new p(sc.nextInt(),sc.nextInt()); } Arrays.sort(p,1,n+1); pp[] pp = new pp[n+1]; for(int i=1;i<=n;i++) { pp[i] = new pp(p[i].a,p[i].b); } int st = 1,ed = 1; while(true) { while(st<=n&&ed<=n&&pp[st].b==pp[ed].b)ed++; Arrays.sort(pp,st,ed); st = ed; if(st>n)break; } int k = n-m; int t = 0; while(k>0&&pp[k].b==pp[n-m+1].b) { k--;t++; } int ans = m + t; System.out.println(pp[n-m+1].b + " " + ans); for(int i=n;i>n-m-t;i--) { System.out.println(pp[i].a + " " + pp[i].b); } } } } class p implements Comparable<p>{ int a,b; public p(int a,int b) { this.a = a; this.b = b; } @Override public int compareTo(p p) { return b-p.b; } } class pp implements Comparable<pp>{ int a,b; public pp(int a,int b) { this.a = a; this.b = b; } @Override public int compareTo(pp pp) { return pp.a-a; } }
分享
滴滴
官网直投
相关推荐
投递华为等公司10个岗位 >
点赞 评论 收藏
转发
投递阿里巴巴控股集团等公司10个岗位 >
点赞 评论 收藏
转发