Java蓝桥杯 小b的宿舍

在这里插入图片描述
其实答案都有,主要的解释和注意点讲一下。
我的答案:(测评通过 与答案有所不同)

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));
		}
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值