其实答案都有,主要的解释和注意点讲一下。
我的答案:(测评通过 与答案有所不同)
import java.util.*;
import static java.lang.Integer.max;
public class Main {
static Vector<Integer> anss =new Vector<Integer>();//创建一个容器来存储答案。
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int N=sc.nextInt();//我这边最好写T(题目上要求),我写了N,但是并不影响后面的代码和逻辑。
int from,to;
int T;
for(int i=0;i<N;i++) {
int maxans=0;
T=sc.nextInt();
int arr[] =new int[205];
for(int j=0;j<T;j++) {
from=sc.nextInt();
to=sc.nextInt();
if(from>to) {//定义好像一个方向为正,如果与此方向相反那么就调换位置,使其方向变正。
int temp =from;
from =to;
to =temp;
}
for(int a=(from+1)/2 ; a<=(to+1)/2;a++) {//因为每一个位置有两个房间,所以要对应到相应的数组位置上。
arr[a]++;
maxans=max(arr[a],maxans);
}
}
if(maxans%2==1) {//因为一条路可以走两个人,那么如果有多一个路只是走一个人那么maxans/2+1。
anss.addElement((maxans/2+1)*10);
}else {
anss.addElement(maxans/2*10);
}
}
for(int i=0;i<anss.size();i++) {
System.out.println(anss.get(i));
}
}
}