zoukankan      html  css  js  c++  java
  • 餐盘模拟 数据结构及其描述

    如何模拟向餐盘中添加物品

    po上来证明我来过

    package ObjectWash;
    
    public class Object {
    	String name;
    	int WashingCost;
    	int TransCost;
    	int length, width;
    
    	Object(String mingcheng, int xishuanshijian, int zhuanyishijian, int chang, int kuan) {
    		this.name = mingcheng;
    		this.WashingCost = xishuanshijian;
    		this.TransCost = zhuanyishijian;
    		this.length = chang;
    		this.width = kuan;
    	}
    
    	public int[][] CalSize(int length, int width) {
    		int[][] array = new int[length][width];
    		for (int i = 0; i <length ; i++)
    			for (int j = 0; j <width ; j++) {
    				array[i][j] = 1;
    			}
    		return array;
    	}
    	void ObjectRotate(Object a) {//将待过机物品旋转90度
    		int Otemp=a.length;
    		a.length=a.width;
    		a.width=Otemp;
    		System.out.println(a.name+"旋转后样式如下:
    ");
    		a.showObj(a);
    	}
    	void showObj(Object a) {
    		int[][] arr=a.CalSize(length, width);
    		System.out.println(a.name+"的样式为:");
    		for(int i=0;i<length;i++) {
    			
    			for(int j=0;j<width;j++) {
    				System.out.print(arr[i][j]+" ");
    			}
    			System.out.println(" ");
    		}
    		System.out.println(" ");
    	}
    }
    
    
    package ObjectWash;
    
    public class Dish {
    	char DishNum;
    	int[][] DishSpace = new int[6][6];// 过机盘的空间为6*6
    	Object[] waitList = new Object[20];
    
    	Dish(char Name) {
    		this.DishNum = Name;
    	}
    
    	int[] CheckIn(Dish a, Object b) {// 遍历过机盘,返回第一个可以插入的位置索引
    		int[] set = new int[2];
    		all: for (int i = 0; i < 6; i++) {
    			if (5 - i < b.width) {
    				continue;
    			}
    			a: for (int j = 0; j < 6; j++) {
    				if (5 - j < b.length) {
    					continue;
    				}
    				if (a.DishSpace[i][j] == 0) {
    					set[0] = i;
    					set[1] = j;
    				}
    				int area = 0;
    				for (int k = set[0]; k < b.length; k++) {
    					for (int m = set[1]; m < b.width; m++) {
    						if (a.DishSpace[k][m] == 0) {
    							area += 1;
    						} else {
    							continue a;
    						}
    					}
    				}
    				if (area == (b.length * b.width)) {
    					break all;
    				}
    			}
    		}
    		return set;
    	}
    
    	void showDish(Dish a) {// 展示过机盘
    		System.out.print("过机盘" + a.DishNum + "的状态为:");
    		for (int i = 0; i < 6; i++) {
    			System.out.println(" ");
    			for (int j = 0; j < 6; j++) {
    				System.out.print(a.DishSpace[i][j] + " ");
    			}
    		}
    		System.out.println(" ");
    	}
    
    	boolean CompareArea(Dish a, Object b) {// 比较过机盘空闲空间和物品体积,能装下为真
    		int area = 0;
    		for (int i = 0; i < 6; i++) {
    			for (int j = 0; j < 6; j++) {
    				if (a.DishSpace[i][j] == 0) {
    					area += 1;
    				}
    			}
    		}
    		if (area < (b.length * b.width)) {
    			return false;
    		} else {
    			return true;
    		}
    	}
    
    	void inDish(Dish a, Object b) {
    		int x=0;
    		int y=0;
    		a: for (int i = 0; i < 6 - b.length; i++) {
    			b: for (int j = 0; j < 6 - b.width; j++) {
    				if (a.DishSpace[i][j] == 1) {
    					continue b;
    				} else {
    					c: for (int k = i; k < 6 - b.length; k++) {
    						d: for (int m = j; m < 6 - b.width; m++) {
    							if (a.DishSpace[k][m] == 1) {
    								continue b;
    							}
    						}
    					}
    				}
    				x=i;
    				y=j;
    				break a;
    			}
    		}
    		for(int i=x;i<b.length+x;i++) {
    			for(int j=y;j<b.width+y;j++) {
    				a.DishSpace[i][j]=1;
    			}
    		}
    		System.out.println(b.name+"插入过机盘:"+a.DishNum+"成功!");
    		a.showDish(a);
    	}
    
    	boolean judge(Dish a, Object b, int i, int j) {
    
    	}
    }
    
    
    package ObjectWash;
    
    public class MainTest {
    	public static void main(String[] args) {
    		Dish a=new Dish('B');
    		Object o1=new Object("粉盒",20,50,2,1);
    		Object o2=new Object("原子弹",0,0,50,60);
    		Object o3=new Object("保时捷",0,0,5,2);
    		
    		o1.showObj(o1);
    		o3.showObj(o3);
    		a.inDish(a,o3);
    		a.inDish(a, o1);
    		o1.ObjectRotate(o1);
    		a.inDish(a, o1);
    	}
    
    }
    
    
  • 相关阅读:
    投票练习
    多条件查询
    PHP 购物车
    PHP TP模型
    PHP smarty函数
    PHP smarty复习
    PHP smarty缓存
    PHP phpcms
    php smarty查询分页
    PHP Smarty变量调节器
  • 原文地址:https://www.cnblogs.com/rrrrraulista/p/11723113.html
Copyright © 2011-2022 走看看