平台重叠真的坑
给你一句样例,如果你觉得自己的代码没问题那就试试吧
2
1 1 3
1 0 4
正确答案
0 0
0 0
P1105 平台 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
import java.awt.Checkbox;
import java.awt.PageAttributes.OriginType;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.math.MathContext;
import java.security.PublicKey;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;
import javax.print.attribute.standard.JobMessageFromOperator;
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Scanner scanner=new Scanner(System.in);
BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw1=new PrintWriter(System.out);
String[] aStrings=br1.readLine().split(" ");
bb=Integer.parseInt(aStrings[0]);
aa1=new pingtai[bb];
cc=new int[bb][2];
int a;
for(a=0;a<bb;a++) {
String[] bStrings=br1.readLine().split(" ");
int b=Integer.parseInt(bStrings[0]);
int c=Integer.parseInt(bStrings[1]);
int d=Integer.parseInt(bStrings[2]);
aa1[a]=new pingtai(b, c, d,a);
}
Arrays.sort(aa1);
int e;
int l=0,r=0,h=0;
for(a=0;a<bb;a++) {
//System.out.println(aa1[a]);
r=l=-1;
for(e=a+1;e<bb;e++) {
if(aa1[a].heigh!=aa1[e].heigh) {
if(r>-1&&l>-1) {
break;
}
if(l==-1&&aa1[e].left<aa1[a].left&&aa1[e].right>aa1[a].left) {
l=aa1[e].xuhao+1;
}
if(r==-1&&aa1[e].right>aa1[a].right&&aa1[e].left<aa1[a].right) {
r=aa1[e].xuhao+1;
}
}
}
if(r==-1) {
r=0;
}
if(l==-1) {
l=0;
}
cc[aa1[a].xuhao][0]=l;
cc[aa1[a].xuhao][1]=r;
}
for(int k=0;k<bb;k++) {
pw1.println(cc[k][0]+" "+cc[k][1]);
}
pw1.flush();
pw1.close();
}
public static pingtai[] aa1;
public static int bb;
public static int[][] cc;
}
class pingtai implements Comparable<pingtai>{
int heigh;
int left,right;
int xuhao;
public pingtai(int heigh, int left, int right, int xuhao) {
super();
this.heigh = heigh;
this.left = left;
this.right = right;
this.xuhao = xuhao;
}
@Override
public int compareTo(pingtai o) {
int a=o.heigh-this.heigh;
if(a==0) {
a=this.xuhao-o.xuhao;
}
return a;
}
@Override
public String toString() {
return "pingtai [heigh=" + heigh + ", left=" + left + ", right=" + right + ", xuhao=" + xuhao + "]";
}
}