历届真题 泊松分酒【第三届】【省赛】【本科组】蓝桥杯 Java

package zhenti;

import java.util.ArrayList;
import java.util.Scanner;

public class daoyou {
	static int rongqishuliang = 3;
	static boolean isfouchenggong = false;
	static int mubiao = 0;
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		rongqi rongqis[] = new rongqi[3];
		int templist[][] = new int[2][rongqishuliang];
		for (int i = 0; i < templist.length; i++) {
			for (int j = 0; j < templist[0].length; j++) {
				templist[i][j] = scanner.nextInt();
			}
		}
		mubiao = scanner.nextInt();
		scanner.close();
		for (int i = 0; i < rongqishuliang; i++) {
			rongqis[i] = new rongqi(templist[0][i], templist[1][i]);
		}
		Integer list[] = new Integer[3];
		for (int i = 0; i < list.length; i++) {
			list[i] = rongqis[i].cunliang;
		}
		ArrayList<Integer[]> arrayList = new ArrayList<>();
		arrayList.add(list);
		daoyoufanfa(rongqis, arrayList);
		
	}
	public static boolean nengfoucharu(ArrayList<Integer[]> arrayList, Integer[] list) {
		for (int i = 0; i < arrayList.size(); i++) {
			Integer[] temp = arrayList.get(i);
			if (shifouxiangdeng(temp, list)) {
				return false;
			}
		}
		return true;
	}
	
	public static boolean shifouxiangdeng(Integer[] list1, Integer[] list2) {
		int length = list1.length;
		for (int i = 0; i < list2.length; i++) {
			if (list1[i] != list2[i]) {
				return false;
			}
		}
		return true;
	}
	
	public static boolean jiance(rongqi[] rongqis, int rongqishuliang ) {
		for (int i = 0; i < rongqishuliang; i++) {
			if (rongqis[i].cunliang == mubiao) {
				return true;
			}
		}
		return false;
	}
	
	public static void daoyoufanfa(rongqi[] rongqis ,ArrayList<Integer[]> arrayList) {
		if(jiance(rongqis, rongqishuliang)) {
			isfouchenggong = true;
			for (int i = 0; i < arrayList.size(); i++) {
				Integer[] tempIntegers = arrayList.get(i);
				System.out.println(tempIntegers[0] + " " + tempIntegers[1] + " " + tempIntegers[2]);
			}
			return ;
		}
		if(!isfouchenggong) {
			for (int i = 0; i < rongqis.length; i++) {
				for (int j = 0; j < rongqis.length; j++) {
					if(i != j && !isfouchenggong) {
						rongqi iRongqi = new rongqi(rongqis[i].rongliang, rongqis[i].cunliang);
						rongqi jRongqi = new rongqi(rongqis[j].rongliang, rongqis[j].cunliang);
						rongqis[i].daoru(rongqis[j]);
						Integer[] list = new Integer[rongqishuliang];
						for (int k = 0; k < list.length; k++) {
							list[k] = rongqis[k].cunliang;
						}
						if (nengfoucharu(arrayList, list) && !isfouchenggong) {
							arrayList.add(list);
							daoyoufanfa(rongqis, arrayList);
							if (!isfouchenggong) {
								arrayList.remove(list);
							}
						}
						rongqis[i] = iRongqi;
						rongqis[j] = jRongqi;
					}
				}
			}
		}
	}
}

class rongqi{
	int rongliang;
	int cunliang;
	
	public rongqi(int rongliang, int cunliang) {
		this.rongliang = rongliang;
		this.cunliang = cunliang;
	}
	
	public void daoru(rongqi beidaoru) {
		int yuliang = beidaoru.rongliang - beidaoru.cunliang;
		if (this.cunliang <= yuliang) {
			beidaoru.cunliang = beidaoru.cunliang + this.cunliang;
			this.cunliang = 0;
		}else {
			this.cunliang = this.cunliang - yuliang;
			beidaoru.cunliang = beidaoru.rongliang;
		}
	}
}

//	 12 8 5 12 0 0 6

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值